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);





Friday, October 11, 2013

Loop through SQL values without a cursor.


3rd Time I had to recreate this example so I'm posting it now.


   1:   
   2:  DECLARE @Users TABLE( 
   3:    [RowNumber] Int  PRIMARY KEY,
   4:    [UserId] uniqueidentifier)
   5:   
   6:  DECLARE @iCount Int
   7:   
   8:  INSERT INTO @Users (RowNumber, UserId)
   9:  SELECT rank() Over (order by UserId)
  10:          ,UserId
  11:  FROM Profile
  12:  WHERE PropertyValuesString like '%ReportPending%'
  13:   
  14:   
  15:  SET @iCount=1
  16:  WHILE ((SELECT MAX(RowNumber) FROM @Users) >= @iCount)
  17:  BEGIN
  18:   
  19:          SELECT * FROM @Users WHERE RowNumber = @iCount
  20:          SET @iCount=@iCount+1
  21:  END

Wednesday, October 9, 2013

Working on my first WPF application from scratch

At work, the project I manage (MVC web app has a WPF installer) had a couple of installer related issues.  I've been on this project ~2 years  and up to now I had no reason to modify the WPF installer app.  I need to determine if the project is going to keep the WPF installer or go with a NSIS based installer.  I reviewed the code and came to the conclusion I know very little about WPF.

So last Friday, I started a small WPF project.  I have a little Lego Parts app I have rewritten a couple of times that currently has a WinForms MDI UI.  Obviously my Lego app needs a WPF UI client.

I thought I would capture my thoughts on WPF.

WPF Cons

  • On controls, renamed Text properly to Content.  This is just annoying.
  • Not all controls (example DataGridColumn) have a Name property.
  • XAML - Maybe unfair on day 1 to say this and yes I'm using yesterday;s tech with VS 2010 but it can be so sloooooow.
  • Property windows for WPF controls/Pages etc...  is terrible.  No really good way to getting to the properties I really use often.
  • Unavoidable not annoying differences in names of method and properties differences between a WPF control and its WinForm counterpart.
  • WPF UI is still a bit slower than its WinForms alternative even on a i7 CPU 3.3 Ghz with a middle of the road video card.


WPF Pros

  • XAML - (4 hrs in).  Now I get it.  Once you know a control / page / window property you want to modify just edit the XML.  This is a huge time saver for repetitive tasks.  Plus this compensates for the terrible VS 2010 properties sheet UI.
  • UI elements.  I like page view paradigm.  
    • I really like DataGrid.  Fantastic that the grid keeps its position when itemsource is updated.
  • Extracting InvokeRequired from UI.  This is completely different in WPF but I like the change. It should never have been married to the Control in WinForms.
  • Data Binding approach is streamlined and simple.
  • Basic settings for UI controls moves so far beyond WinForms.  Colored backgrounds, transparency etc...


Bottom line, in under 8 hours, I managed to restructure an existing C# solution to keep the existing WinForms UI project, move common code out of WinForms UI project, and create the basic elements of WPF UI in a new project.

  

Tuesday, October 1, 2013

Snipe Hunt: Finding best way to delete large number of files in Windows 7

Attempting to defrag my hard drive recent and one of the largest fragmented folders was:

C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5

Turns out this folder had over 39 million files taking up 60 GB of drive space.
So it begs the question how do you delete a huge number of files from Windows 7.

Turns out this is the approach I am currently using:

del /f/s/q %1 > nul 
rmdir /s/q %1

from http://www.anushand.com/2012/09/a-faster-way-to-delete-large-folders-in.html

I've estimated it will take ~ 4 days to delete all of these files.

My steps:

1. Rename folder Content.IE5 to (old) Content.IE5
2. Run
                del /f/s/q %1 > nul 
                rmdir /s/q %1

                del /f/s/q "(old) Content.IE5\CAY*.*"