Friday, September 16, 2011

"How to" SVN Merge with TortoiseSVN

Suppose, you have a branch feature that you'd like to merge back into the trunk.

If there have been no changes to the trunk since you've been working on your branch, you can simply follow the steps below to merge your branch to trunk (branch -> trunk).

However, if there have been changes to the trunk while you've been working on your branch, then you should:

1.First, merge trunk to branch (trunk->branch) to update your branch with the latest trunk changes.

2.Then merge your new features from branch to trunk (branch->trunk).

Merge branch to trunk (branch->trunk)

1.Commit all code in your working directory.

2.Switch your working directory to the trunk:

3.Next, Merge...

4.In the merge window, we need to make sure we are going "FROM" the trunk "TO" our branch. The reasoning behind this is that we are doing a DIFF between the trunk and the branch. Or, starting "FROM" the trunk's current state "TO" our branch's state. The trunk is the starting point for the branch changes.

5.Now that the diff has been calculated, the results are stored in your working directory. You'll need to commit these results into the /trunk to finalize the merge.

Merge trunk to branch (trunk->branch)

1.Commit all code in your working directory.

2.Make sure that your current working directory is your branch. (Use Switch to... )

3.Next, Merge...

4.The "FROM" text box should be the URL to the /trunk. Why isn't it the URL to the branch? Well, your branch doesn't have the changes that you're looking for in /trunk because we're trying to update our branch with changes in the trunk. Effectively, what we want to do is perform a DIFF between the last time your branch was synchronized with the trunk and the head version of the trunk with the latest changes. This is why "FROM" URL is set to /trunk and the revision number is set and the "Use 'FROM' URL" is set with "HEAD" revision.


In my case below r25 was the last time the base of my branch was synchronized with the trunk. I want to "REPLAY"/"DIFF" all changes that happened from the time my last branch (r25) was synchronized with the base of the "/trunk" up "TO" the current "HEAD reversion". The result of this merge should be stored in my current working directory (which points to my /branch/cowboy).

5.Once the merge happens, you're branch should now be synchronized with the /trunk. You'll want to "Commit" the result of the diff and add a special note in the message that indicates what revision you're working copy is based on.

Hope that helps!

Thursday, September 15, 2011

VS Debug Problem with IE8

Since this is my first post on Weblogs, I decide to write about a problem that has been opened frequently on ASP.NET official forum which is VS debugger crashes with IE8.


I had answered the same problem 4 times, so I hope that some one will found this post very helpful if he is facing the same problem.
How VS debugger could be crashed with IE8?

If you opened multiple instances of IE8 and you attempt to debug your project, you mostly will have the issue where VS debugger just stops and ignores your break points!

Why was that?

Well, IE 8 has a feature called Loosely-Coupled Internet Explorer (LCIE) which results in IE running across multiple processes.


http://www.microsoft.com/windows/internet-explorer/beta/readiness/developers-existing.aspx#lcie

Older versions of the Visual Studio Debugger get confused by this and cannot figure out how to attach to the correct process.


To overcome this issue, you need to disable the process growth feature of LCIE by follow the below steps:

1) Open RegEdit
2) Browse to HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
3) Add a dword under this key called TabProcGrowth
4) Set TabProcGrowth to 0

If you run into the same problem on Vista or newer, you will also need to turn off protected mode.
And then go a head and start debugging your code :)

Error:The backup set holds a backup of a database other than the existing database

USE [master]



RESTORE DATABASE Ambio360SProd


FROM DISK = 'C:\Ambio360S-15092011-0222am.bak'


WITH REPLACE

Tuesday, September 13, 2011

SQL Server CLR in SQL Server 2008

Eg. Remove HTML tags for the string.


First, make sure that the CLR integration is enabled. This can be accomplished by using the server facets in SQL Server 2008, the Surface Area Configuration tool 



sp_configure 'clr enabled', 1  
GO  
RECONFIGURE  
GO

Next, follow these steps:
  • Open Visual Studio 2010
  • Click on "New Project"
  • Choose the Database ---> SQL Server ---> Visual C# SQL CLR Database Project template.
  • Make sure that the project targets .NET 2 / .NET 3 / .NET 3.5.
  • Set up a connection to your database, test the connection and click OK
  • Right click on the project and add a user defined function as explained in the next section




Creating the user defined function in the SQL Server CLR


 [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString RemoveHTMLTags(SqlString s)
    {
        if (s.IsNull) return String.Empty;
        string s1 = s.ToString().Trim();
        if (s1.Length == 0) return String.Empty;
        string pattern = @"<[^>]*?>|<[^>]*>";
        Regex rgx = new Regex(pattern);
        return rgx.Replace(s1, String.Empty);
    }

Create Assembly and Function

After the code has been compiled you need to create the assembly and the function with SQL Server.  To do this, run these commands in the database where you want to use the function. 
The assembly ties an internal object to the external DLL that was created and the function is similar to a normal SQL Server function.

For the function you will see three components that are referenced CLRFunctions.CLRFunctions.SortString.
  • CLRFunctions - the assembly reference.
  • CLRFunctions - the class reference in the C# code.
  • SortString - the function reference in the C# code.

CREATE ASSEMBLY CLRFunctions FROM 'C:\
RemoveHTMLTags
.dll'  
GO
CREATE FUNCTION dbo.
RemoveHTMLTags

(   
 
@name AS NVARCHAR(255)   
)     
RETURNS NVARCHAR(255)    AS EXTERNAL NAME 
RemoveHTMLTags
.
UserDefinedFunctions
.
RemoveHTMLTags

GO



To Test the Data



SELECT dbo.RemoveHTMLTags('Hello World')

Accessing Master Page function from Child Page.

ClassName MasterPage = (ClassName)Page.Master;
MasterPage.MasterMethod();

 Replace the ClassName with the name of your code-behind class, and MasterMethod() with the name of the master page method you will be accessing.

Creating Reports in C# using Crystal Reports with Xml data Definitions


This article explains how to extract data into a Crystal Report created outside a C# project using xml data definitions and data sets.

In this project,
  • The report is formatted outside the project via Crystal Reports (the .rpt file)
  • The data to the report is extracted from a field definition file created as a .xsd extension (as compatible with ADO.Net)
  • The report is called and displayed through a form using the crystal report viewer.
We have taken the Authors table in the pubs database where au_id, au_lname, au_fname will be printed on the report.

The main requirement is to create the Xml schema file with .xsd extension and bind the data to the .rpt file.

The example handles this in one form with two buttons: The XSD Button to create the .xsd field definition file and the VIEW button to generate the report.

So here is the step by step procedure to arrive at this.

1. Create the .xsd field definitions file depending on the data that we want to extract from a database.

Insert the following code in the click event of XSD button, to create the .xsd file. In our example this file is called the 'sampledatadef.xsd'. 


#region private void SetSource()
        private void
SetSource()
        {
            rptReceipt rpt = new rptReceipt();           
            Receipt dsReceipt = new Receipt();               
            DataTable dtReceipt = new DataTable();
                   
            dtReceipt = dsReceipt.dtReceipt;
                    
//LINQ - SQL datasource
            List source= Rules.Receipt.GetReceiptByCustomerId(custId);


            foreach (Receipt_SelectResult item in source)
            {
                DataRow drReceipt = dtReceipt.NewRow();
                drReceipt["Order_No"] = item.Order_No;
                drReceipt["Status"] = item.Status;
                drReceipt["Cust_Name"] = item.Status;
                drReceipt["Phone_No"] = item.Phone_No;
                drReceipt["Booking_Date"] = item.Booking_Date;
                drReceipt["Delivery_Date"] = item.Delivery_Date;
                drReceipt["Advance"] = item.Advance;
                drReceipt["Balance"] = item.Balance;
                drReceipt["Refund"] = item.Refund;
                drReceipt["SlNo"] = item.SlNo;
                drReceipt["Details"] = item.Details;
                drReceipt["Quantity"] = item.Quantity;
                drReceipt["Rate"] = item.Rate;
                drReceipt["Category"] = item.Category;
                drReceipt["Desc"] = item.Desc;
                dtReceipt.Rows.Add(drReceipt);
            }

            rpt.SetDataSource(dsReceipt);
            crvPrintPreview.ReportSource = rpt;
        }          
        #endregion 
   

2. Now create the .rpt file in crystal reports using the .xsd field definitions file.

You need to select 'Create new Connections' and take option - Field Defintions. Select the ADO.NET option. In the dialogue box you will be asked to enter the xsd file name. Select the path and click the 'Finish' button. 

We have named this report as crystalsample.rpt (saved in c:\)

If the ADO.Net option is not available, you will have to add new components to the installed crystal reports using 'Add/Remove' programs option and include the necessary component to the Crystal Reports installation.


3. Generate the class to hold the data set for the .xsd datadefiniton
 
This is an important step. The .xsd definitions do not recognize the datasets generated through the normal DataSet class. The report will be displayed only with the headings, if this step is not accomplished!!! (This was a weird experience to us).

This is done though executing the following command through the command prompt tool of the Visual Studio .Net Tools.
xsd.exe /d /l:C# sampledatadef.xsd 

(The /d directive tells the tool to generate DataSets, /l specifies the language to use)

This command generates the DataSet class compatible with the .xsd file you created in the path in which you executed the command. The name of the source file will be sampledatadef.cs.

 4. Now add this class to your project.In the source file, the name of the class will be generated as 'NewDataSet'. Rename this name to a name that you desire in the source file. We have named it as ds_SampleDataSet.

5. Now generate the code to extract the data from field definition
In our example we have used a new form for this, which is loaded with the click event of the VIEW button.
This is done in an easy set of steps.
  1. Define a dataset of the newly generated type. In this example
    Private ds_sampledataset mydataset = New ds_sampledataset() 
  2. Fill this dataset with the identical data fields that you created for the xsd definition file. In this example they are au_id, au_lname, au_fname of Authors.  
  3. Open a new ReportDocument type class and call the .rpt file you created into it. (Make sure that the necessary references are added to the project - CrystalDecisions.CrystalReports.Engine CrystalDecisions.Shared )