- A recent task required me to populate and existing table inside an Microsoft SQL database from a flat .txt file. The T-SQL Bulk Insert command performed the task nicely.
Step 1: Create Format File with the bcp command. (If your your input and output file layouts are alike, this step may not be necessary.)
Log on to the machine where the database resides. Open up a command window and navigate to the binn directory (Program Files\Microsof Sql Server\...). The binn directory is where the bcp command resides.
From the command line enter:
bcp DatabaseName.Owner.TableName format nul -S ServerName -T -n -f Products.fmt
For more information on creating a format file see http://msdn.microsoft.com/en-us/library/ms191516.aspx
Step 2: Run Bulk Insert Command
--Without Format File
Bulk Insert dbo.fp_Products_work
From 'D:\temp\Products.txt'
With(FirstRow=2)
--With Format File
Bulk Insert dbo.fp_Products_work
From 'D:\Chuck\Products.txt'
With(FirstRow=2, FormatFile='D:\temp\Products.fmt')
Gotchas: 1) Your SQL Server account must be a member of the sysadmin or bulkadmin roles in order for you to use the Bulk Insert command. 2) In SQL 2000, the From clause does not allow you to use a variable (@Path) to provide path informatioin. My workaround in my stored procedure was to dynamically create an SQL string, and then execute the sql like so: Exec (@sql.
- Working with the DataGrid Control: Dynamic Bound Columns OnSortCommand event not being called.
Problem: The event/routine specified in the OnSortCommand attribute in the aspx:datagrid control was not being fired. I was also binding the datagrid columns dynamically in the code behind page.
Fix: When binding columns in the DataGrid dynamically, do so in the Page_Init event. By doing so, the event fired, and I was then able to sort the data.
Helpful Links: http://www.velocityreviews.com/forums/t97260-dynamic-bound-columns-onsortcommand-not-called-solution.html
I posted code on the link below showing how to sort columns in an ascending and descending manner.
http://www.codeproject.com/KB/webforms/SortingDataGridColumns.aspx
- Adding filter action to the ASP.NET FileUpload Control
Problem: The FileUpload control does not have a property to specify filter action on the FileUpload control. The following link provides techniques for filtering on both the client and server side: Adding Filter Action to FileUpload control of ASP.NET.
56d01603-e651-42f4-b611-7f140abd65bf|0|.0
I am a big fan of Sara Ford's tips and tricks blog. I met her recently at the devLink conference in Nashville, TN.
One of my favorite tips, is how you can configure a macro to increase or decrease you font size from within your Visual Studio IDE. It is tip 242.
Sara has also recently written a book, Microsoft Visual Studio Tips, which will be released in October.
---------------------------------
Here is a new webdevloper tips and tricks blog I found out about from Brad Abrams' blog: http://blogs.msdn.com/webdevelopertips/default.aspx
Another one that has been around for awhile is Scott Guthrie's tips and tricks page.
John
b6975674-e979-4e21-b355-90f133e36def|0|.0
- To find out the what version of Microsoft SQL you are running, execute the following T-SQL command: Select @@Version. Here is a link for more information.
- With the ToString() method, there is a method overload that allows you to perform formatting. For example,
Dim decimalCount As New Decimal
decimalCount = cmd.ExecuteScalar()
Return decimalCount.ToString("##0.0")
- Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it
I had to work around this error recently, when trying to render an Excel spreadsheet in an ASP.NET application. The crux of the problem is the AJAX Update panel. The client javascript for the update panel gets confused when rendering HTML in "partial PostBack mode." The quick fix for me, was to added a PostBack trigger to the Update Panel that pointed to the button that started the Excel spreadsheet creation. This step forced the application to do a normal PostBack. For a more detailed explanation, follow the link above.
- Setting ViewState items in Page_Init sub of code behind did not persist. That is, the settings disappear. Moved settings to Page_Load and the settings persisted. 09/12/2008 ViewState loaded in PreLoad Page Event. See ASP.NET Page Life Cycle Overview and ASP.NET Application Life Cycle Overview.
- To remove commas from text fields, try the Decimal.Parse method. For example, Decimal.Parse(txtDollarAmount.Text).
dc1e1240-a31a-4f68-9232-974f17204219|0|.0
I picked this up from Scott Michell's blog and thought I pass the word. Scott Hanselman has a web page on his blog that provides a comprehensive list of developer tools. He updates the list annually. I think it is fantastic. Here is the link Ultimate Developer and Power Users Tool List.
John
d3dbad92-6b75-4206-8984-bd2e6a27d9ee|0|.0
I recently purchased Camtastia Studio 5 in order to create "How To" videos. My first "How To" video, How Do I: Return a text/value pair or key/value pair to the Ajax AutoCompleteExtender is now available under the Presentations menu tab on my web site www.JohnStagich.com
This video (.wmv) shows how to get a web service to return a text/value or key/value pair to the Ajax AutoCompleteExtender.
John
2af0aba9-0e5c-48b8-9347-64eeae5b16d3|5|3.0
Recently, I have been seeing an Apple commercial on TV that rags on Vista. I am starting to think Apple may have a legitimate point.
I go and insert a CD into my DVD/CD drive. I open my Windows Explorer and I do not see my DVD/CD-ROM drive. Ok, what is going on. I have not installed any new hardware or added or removed any programs recently (other than Vista updates). I proceed to Control Panel->Hardware and Sound->Device Manger->DVD/CD-ROM drives. Sure enough, there was an error icon on top of the drive. I select properties and see the following message:
Windows cannot load the device driver for this hardware. The driver may be corrupted or missing. (Code 39)
OK, there is a button to click on to help solve the problem. I click on the button--totally useless. I then resort to Googling on the error message and came up with the following fix: http://support.microsoft.com/default.aspx?scid=kb;EN-US;314060 (use Method Two), which involved deleting two entries from the registry and rebooting my PC. The fix worked and I was able to see my DVD/CD-ROM drives.
We are now almost half-way through 2008, and I am working with an OS that
-
Does not notify me that a critical hardware device is not working.
-
Provides no immediate help to fix the problem.
-
Requires me to perform an arcane maneuver to fix the problem.
I believe Vista is a big improvement over XP; however, a basic problem like I described above should not be happening.
714dcc6e-5bb4-4a44-9dde-2a00986fabc9|1|5.0
I picked this information up from a Dave Hayden blog post.
ZoomIt is a Screen Zoom and Annotation Tool for Technical Presentations created by Mark Russinovich and it is FREE!
Here is a brief description of the tool from the download page:
ZoomIt is screen zoom and annotation tool for technical presentations that include application demonstrations. ZoomIt runs unobtrusively in the tray and activates with customizable hotkeys to zoom in on an area of the screen, move around while zoomed, and draw on the zoomed image.
I downloaded the application and tried it out in my Visual Studio 2008 IDE. It worked great and it is super easy to use.
John
79bf7d4d-6bf5-4887-a136-846db845f955|0|.0
I was doing some maintenance on my laptop this week, and one of my tools suggested creating a Password Reset Disk. I did not know the feature even existed. Anyway, it seems like a good idea. It is simple to do, and you can use multiple types of media (SD Disk, Thumb Drive, CD, etc.) to store the file that is created: userkey.psw. Here are a few links that show you how to create and use the Password Reset Disk.
http://support.microsoft.com/kb/930381
http://www.vistax64.com/tutorials/102005-reset-user-account-password.html (See Method Four)
John
c34105a5-1d99-4e41-bb88-1f3d96a2c3ee|0|.0
Last week I noticed high processor usage on my laptop. (I was using Process Explorer http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx to monitor my system.) The culprit was an application called TrustedInstaller.exe. I did some research and found a page on Scott Hanselman’s blog that described a similar situation: http://www.hanselman.com/blog/MSMPENGEXETrustedInstallerexeSearchIndexerAndSLSVCEXEAt100CPUOnMyVistaMachines.aspx. It suggested upgrading to Vista Service Pack 1 to fix the problem.
Ok, I go to upgrade: Control Panel->Security->Check for Updates, and I find no SP1 upgrade. What is the deal? After doing some more research, it turns out that one of my optional updates that I had not installed was not so optional. I needed to upgrade my Conexant HD Audio driver. Here is the link where I found that information: http://support.microsoft.com/kb/948343. I installed the Conexant HD Audio driver, and still no sign of SP1 when I check for updates. I then install all of the remaining optional Windows Vista updates (not the Windows Ultimate Extras and not the Windows Vista Ultimate Language Packs) and restart my laptop. I check for updates again and FINALLY the SP1 upgrade appears. An hour later, Vista Service Pack 1 is successfully installed on my PC.
I then get into my Visual Studio 2008 IDE and notice that I cannot debug my application. I get the following error: Unable to start debugging on the web server. Unable to connect to the web server. Verify that the web server is running and that incoming HTTP requests are not blocked by a firewall.
I do some more research and find that I need to start the World Wide Web Publishing service. For some reason, it is not started. That fixed the debugging problem in the Visual Studio 2008 IDE. Here is the link where I found that information: http://forums.asp.net/p/1235884/2302214.aspx#2302214
To date, I have not had any other issues with Vista SP1, and it did seem to fix the problem with the TrustedInstaller.exe application consuming enormous amounts of CPU time.
John
839e7ca0-e69c-4ccc-9513-cdb57aebae0d|0|.0
Here are some useful and free tools for Web Application troubleshooting:
- IE Developer toolbar (allows editing of loaded pages) http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en
- Fiddler (inspection of HTTP and HTTPS request traffic) http://www.fiddler2.com/fiddler2/
- Firebug add on for FireFox (allows monitoring of page load times, file sizes, etc). http://www.getfirebug.com/
John
88509060-566d-4352-b6c4-c95703c16f00|2|1.0