John Stagich's Blog

Microsoft .Net Developer

March 2010 Quick Hits

clock March 3, 2010 07:34 by author johnstagich
  • Here is way to copy data between tables with the same structure/layout:

Trucate table destination_tablename

Insert Into destination_tablename
Select *  from source_tablename

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


May 2009 Quick Hits

clock May 5, 2009 06:40 by author johnstagich
  • Rick Strahl has a good blog article on adding default Assemblies, Namespaces, and Control Prefixes in your web.config file so that they apply globally.  I believe it makes working with Custom Controls in ASP.Net much easier.

  • I installed some Microsot Updates and my Speaker and Network icons disapeared in my notifcation tray after rebooting.  When I went to the properties for the tray (Taskbar->Right Mouse Click->Properties), in the Notifcation Area tab, in the System Icons panel, the Volume and Network checkboxes where greyed out.  The fix is to go to Task Manager, kill the explorer.exe process, and then restart the explorer process.  To restart, from the Task Manager, File->New Task and enter explorer.exe in the dialog box.  Here is the link where I found this information.

  • Another SQL 2008 feature:  I was trying to connect to the SQL 2008 instance using SQL Server Authentication without success.  The reason?  The Server Authentication mode settings were set to Window Authentication mode only.  I modified the setting to SQL Server and Windows Authentication mode.  To get to this setting, right mouse click on the server instance, select properties, then select the Security Page. Here is link that decribes the process.  After making the change, restart SQL Service (2008).

  • Here is a link to a macro for quickly selecting a complete XAML tag in the Visual Studio designer.  Cut and paste the SelectXAMLTagContent macro using the Visual Studio Macro Editor (Tools->Macros->Edit Macro [you frist have to select a macro from the Macro Explorer in order to activate the Edit Macro menu item]).  I created a new module called WPF under MyMacros and pasted the subroutine into the WPF module.

    Then, to bind the macro to a key combination in Visual Studio 2008, go to Tools->Options->Environment->Keyboard.  Next, enter "macro" in the Show commands containing: dialog box, select the XAML macro (in my case, it was Macros.MyMacros.WPF.SelectXAMLTagContent), and assign your key combination.  I used Cntrl+Shift+Q.

    Here is a link to a How Do I Create and Edit Macros video.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


IE8 and Browser Compatibility

clock April 20, 2009 02:34 by author johnstagich

Last Friday, I updated my browser on my Vista laptop to IE8.  I then checked my web site www.JohnStagich.com with the new browser.   Three of my web pages did not render as they did with IE7.  After spending a good amount of time tinkering with CSS style sheets and the like, I finally was able to get the web pages to look “similar” in IE7, IE8, and Firefox 3.0.8.  What a hassle.  Here is some of the code I used to achieve the similar look:

        var name = Request.Browser.Browser;

        HttpBrowserCapabilities bc;

        bc = Request.Browser;

 

        if (name == "IE" && bc.Version == "8.0")

        {

            btnSend.Style.Add("margin-left", "205px");

        }

        if (name == "IE" && bc.Version == "7.0")

        {

            btnSend.CssClass = "txtFloatLeft";

            btnSend.Style.Add("margin-left", "172px");

        }

        if (name == "Firefox")

        {

            btnSend.CssClass = "txtFloatLeft";

            btnSend.Style.Add("margin-left", "152px");

        }

I then read an article in Computerworld about browser compatibility.  It turns out that Microsoft is making an effort with IE8 to make it much more World Wide Web Consortium (W3W) compliant then previous versions of Internet Explorer.  Hence, the rendering changes of my web site with IE8. 

One developer in the article suggests devloping your web code first with Firefox and then making the necessary adjustments for the IE browsers.

If you are interested in finding out more about the differences between browsers, here is a good reference that contains compatibility tables for the different browser versions: QuirksMode.org.

John

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


November 2008 Quick Hits

clock November 8, 2008 07:42 by author johnstagich
  • Enterprise Library 3.1: Enterpise Library Configuation Editor Problem

An application I was working on needed to run on with the Entiprise 3.1 Library.  When I tried to use the Enterprise Library Configuration editor (EntlibConfig.exe) on my app.config file, I was getting errors that it could not locate the specific libraries/.dll’s.  The problem was that my libraries in my code where strongly named (PublicKeyToken=b77a5c561934e089) while the Enterprise Library Configuration Editory was looking for libraries with the PublicKeyToken set to null (PubliKeyToken=null).  The fix was to use the RIGHT Enterprise Library Configuration editor.  There are two of editors.  One resides in C:\EntLib3Src\App Blocks\bin and the other resided in  C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin.  The former works with non-signed libraries while the latter works with signed libraries.  From the Visual Studio Development environment, I changed app.config editor to point to the C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin editor.

For more information, check out this link from Tom Hollander on Avoiding Configuration pitfalls with incompatible copies of Enterprise Library.

  • How do you debug a Unit Test in Visual Studio 2008?

1) Set a breakpoint in your test, and then from the Visual Studio menu: Test-->Debug-->Tests in Current Context.

2) Set a breakpoint in your test. Go to the Test Results window (from the Visual Studio menu: Test-->Windows-->Test Results).  From the toolbar in the Test Results window, click on Debug drop down icon and then select Debug Checked Tests.

3) Try entering System.Diagnostics.Debugger.Launch() and System.Diagnostics.Debugger.Break() into your Unit Test code and then run your Unit Test  You then will be prompted with a Visual Studio Just-In-Time Debugger dialog box.  Select the default selection.  You should then break into your Unit Test code.

  • Here is a good link to the How Do I Video Series for Visual Basic.
  • For the datagrid view control, if you want the NewRowNeeded event to fire, the VirtualMode property for the datagrid view control needs to be set to true.
  • From Scott Mitchell's blog, I found out about a product called ELMAH that may come in handy down the road.  ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
  • Have you ever wanted to share a common file among project? Check out Sara Ford's tip number #365 that shows how to link a file. (I wonder how this works with Team Foundation Server Source Control?).  Tip number #364 is good too.  Visual Studio comes with an image library.

  • FromScott Gu's blog, new ASP.Net Chart control.

  • The table designer in Microsoft SQL 2005 I find is lacking because I cannot find a way to add properties to the columns displayed.  It only displays Column Name, Data Type, and Allow Nulls.  From Rich Strahl's Web log, comes a work around.  Use the Database Diagram Designer.   Right mouse click on the Database Diagrams folder and click New Database Diagram.  Next add your table.  Right mouse click on the table-->Table View-->Modify Custom...
     

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


October 2008 Quick Hits

clock October 1, 2008 02:43 by author johnstagich
  • SQL Server 2005: Reporting Server Error 1053-The service did not respond to the start or control request in a timely fashion

I am now starting to work with Microsoft Reporting Services (SQL 2005).  The SQL Server Reporting Services service would not start.  It looks like one of the Hot Fixes for SQL 2005 mucked something up.  Anyway, it required a registry fix and a reboot.  Here is the link http://support.microsoft.com/?kbid=884495.  

You may want to check out this link also http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=3639819&SiteID=17


  • Enterprise Library 4.0: Getting Exception Handling and Logging to Work

I have been working with the Enterprise Library 4.0 extensively.  I  had already implented the Data Access and Cryptography application blocks with no problems.  However, I did run into problems with the Exception Handling and Logging Application blocks.  In order to get the Exception Handling to log a message to the Application Event log, I had to add a reference to the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.Configuration.Design.dll (Enterprise Library Exception Handling And Logging Application Block Design) library.  In order to get the Exception Handling to log to the Database, I had to add a reference to the Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll (Enterprise Library Logging Application Block Database Provider) library.  Both of these references were not mentioned in the documentation that I was using.


  • Windows Forms: Controlling Event Firing

While working on a Windows application, the SelectIndexChanged event with the ComboBox control was firing unintentionally. I only wanted the event to fire when the user changed the value in the combo box. Doing some research, I was presented with two options (see link). One, use a boolean flag to monitor what was causing the event to fire. The second was to remove and add the SelectIndexChanged event handler for the ComboBox at appropriate times in your code. I chose the latter. It really is quite simple.


Remove Handler: RemoveHandler comboBoxProduct.SelectedIndexChanged, AddressOf comboBoxProduct_SelectedIndexChanged

Add Handler: AddHandler comboBoxProduct.SelectedIndexChanged, AddressOf comboBoxProduct_SelectedIndexChanged


  • ASP.NET Website Development - Displaying Images from SQL Server Database

I picked this information up from a David Hayden blog post.  I had a project at a former employer where this code could have come in handy.  I can imagine possibly getting a similar request to display images from an SQL database in the future.  Here is the link http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16449


 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Virtual Team System Users Group/ScreenCastADay

clock September 17, 2008 07:27 by author johnstagich

Here are two more Team System/.Net/SQL/ resources.

Team System User Group - Virtual Edition

Screen Cast A Day


John

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


September 2008 Quick Hits

clock September 8, 2008 03:38 by author johnstagich
  1. 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.
 
  1. 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

  1. 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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Tips and Tricks News

clock August 27, 2008 06:05 by author johnstagich

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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


August Quick Hits

clock August 14, 2008 00:59 by author johnstagich
  1. To find out the what version of Microsoft SQL you are running, execute the following T-SQL command: Select @@Version.

  2. With the ToString() method, there is a method overload that allows you to perform formatting. For example,

  3. Dim decimalCount As New Decimal

    decimalCount = cmd.ExecuteScalar()
    Return decimalCount.ToString("##0.0")

  4. Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it

  5. 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.


  6. 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.

  7. To remove commas from text fields, try the Decimal.Parse method.  For example, Decimal.Parse(txtDollarAmount.Text).

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Web Application Troubleshooting Tools

clock March 29, 2008 07:50 by author johnstagich

 

Here are some useful and free tools for Web Application troubleshooting: 

  1. IE Developer toolbar (allows editing of loaded pages)  http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en 
  2. Fiddler (inspection of HTTP and HTTPS request traffic) http://www.fiddler2.com/fiddler2/  
  3. Firebug add on for FireFox (allows monitoring of page load times, file sizes, etc). http://www.getfirebug.com/ 

John

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Search

Calendar

<<  March 2010  >>
SuMoTuWeThFrSa
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Archive

Tags

Categories


Blogroll

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in