Search This Blog

Friday, November 22, 2013

Using BCP utility

Bulk copy program bcp is still supported by SQL 2008 R2 and SQL 2012 Yeah!!!

SQL 2008 R2 http://technet.microsoft.com/en-us/library/ms162802(v=sql.105).aspx
The bcp 10.0 client is installed when you install Microsoft SQL Server 2008 R2 tools. If tools are installed for both SQL Server 2008 R2 and SQL Server 2005, depending on the value of the PATH environment variable, you might be using the earlier bcp client instead of the bcp 10.0 client. This environment variable defines the set of directories used by Windows to search for executable files. To discover which version you are using, run the bcp /v command at the Windows Command Prompt. For information about how to set the command path in the PATH environment variable, see Windows Help.

SQL 2012 http://technet.microsoft.com/en-us/library/ms162802.aspx
The bcp 11.0 client is installed when you install Microsoft SQL Server 2012 tools. If tools are installed for both SQL Server 2012 and an earlier version of SQL Server, depending on the value of the PATH environment variable, you might be using the earlier bcp client instead of the bcp 11.0 client. This environment variable defines the set of directories used by Windows to search for executable files. To discover which version you are using, run the bcp /v command at the Windows Command Prompt. For information about how to set the command path in the PATH environment variable, see Windows Help.

For exporting

bcp [database name].dbo.[table name] out  -n -S -U -P


For Import

bcp [database name].dbo.[table name] out  -n -S -U -P


case is important on arguments.  -n is very important. forces bcp to sql native format.  This is essential of you are exporting and importing data to tables to prevent truncating.

Example

Bcp [New410].dbo.tbCPTDx out tbCPTDx.bcp –n –SRISQA2008R2 –Usa –Psa


Wednesday, November 13, 2013

Creating my first WPF app, the saga continues

In around 60 hrs I have converted a C# winforms application to WPF.

Biggest challenge encountered was the tree control.
In winforms, tree control uses treenodes.  Not the case at all in WPF.

You use HierarchicalDataTemplate


Pretty cool once you get it working.

Next big challenge,  convert sql server data source to SQLite.
Great project on Code Project

Convert SQL Server DB to SQLite DB - CodeProject


But, it converted my Int32 to Int64.

This caused a problem in the class structures I was deserializing the result sets into.

public class LegoPart : INotifyPropertyChanged
    {
        [DataMember, Column]
        public string ItemNo { get; set; }

        [DataMember, Column]
        public string ParentItemNo { get; set; }

        [DataMember, Column]
        public byte[] Image { get; set; }

        [DataMember, Column]
        public string Description { get; set; }

        [DataMember, Column]
        public object Color { get; set; }

        [DataMember, Column]
        public string ImagePath { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
    }






Next problem, I encountered is apparently SQLite does not support UNION queries
This was simple to eliminate since the resultset is being converted into IList. I simply created two lists and then combined them.

   list1.AddRange(list2);