Tuesday, April 27, 2010

Get all triggers in a SQL Database

Ever need to get all the triggers in a SQL database.  This script will return them;


SELECT S2.[name] TableName, S1.[name] TriggerName,
WHEN S2.deltrig =  THEN 'Delete'
WHEN S2.instrig = THEN 'Insert'
WHEN S2.updtrig = THEN 'Update'
END 'TriggerType' , 'S1',s1.*,'S2',s2.*
FROM sysobjects S1 JOIN sysobjects S2 ON S1.parent_obj = S2.[id] WHERE S1.xtype='TR' order by TableName

Silverlight Spy

Silverlight Spy provides detailed runtime inspection of any Silverlight application. Use the built-in browser to navigate to a web page.

Silverlight Spy automatically detects the applications embedded in the page and provides various inspection view panes. Explore the XAP package, Isolated Storage, monitor performance, browse the UI visual and logical tree, examine objects, execute code in the DLR shell and more.

Friday, April 23, 2010

VS2010 Generate From Usage Feature

The Generate From Usage feature enables you to use classes and members before you define them. You can generate a stub for any class, constructor, method, property, field, or enum that you want to use but have not yet defined. You can generate new types and members without leaving your current location in code. This minimizes interruption to your workflow.

Generate From Usage supports programming styles such as test-first development.

Using Generate From Usage in Visual Basic

A wavy underline appears under each undefined identifier, and a short underline appears under the rightmost character. When you rest the mouse pointer on the identifier, an error message appears in a tooltip.

To display the appropriate options, you can use one of the following procedures:

  • Rest the mouse pointer on the undefined identifier. A smart tag (an icon) appears. Click the smart tag.

  • Click the undefined identifier, and then press CTRL+. (period).

  • In the Error List window, double-click the corresponding error row.

The options that appear can include the following:

  • Generate property stub

  • Generate field stub

  • Generate method stub

  • Generate class

  • Generate interface

  • Generate new type (for a Class, Structure, Interface, Enum, Delegate, or Module)

The link below details using this feature.

Connected by Kasey McMahon

This is a self portrait of the artist made from CAT5 cables.


Silverlight 4 Overview Document

This is a link to a great document covering the technical features of the Silverlight 4.

.NET Framework 4 Client Profile - Introduction

Microsoft has introduced client profile versions of the Net Framework (started in 3.5) which can cause some confusion for users.  Below is a great post on what is new with client profiles.

VS2010 Ultimate Trial Extension

If your running the VS2010 ultimate trial and running our of time you can extend the trial an additional 60 days by visiting this link;

Silverlight 4 Training Kit Released

This is a great complete training kit for getting started with Silverlight 4 from Scott Guthrie at Microsoft.  This provides a great step by step introduction to silverlight development for line of business applications.

Link to Scott Gu’s blog.

Link to training course.

Thursday, April 22, 2010


Simplify your XML Comments!

GhostDoc is a free Visual Studio extension that automatically generates XML documentation comments for methods and properties based on their type, parameters, name, and other contextual information.

When generating documentation for class derived from a base class or for interface implementation (e.g. .NET Framework or your custom framework), GhostDoc will use the documentation that Microsoft or the framework vendor has already written for the base class or interface.

It supports VS2005, VS2008 and VS2010!

Getting Started with Visual Studio 2010 Application Lifecycle Features

This is a good webpage on “Getting Started with Visual Studio 2010 Application Lifecycle Features”.

UI Spy (UISpy.exe)

Another good development tool is UI Spy.  This enables developers to view and interact with the US of an application and see the element interactions.

Getting Started with FxCop

While there is some administrative overhead in using FxCop and some of the constraints are questionable (many Microsoft assemblies fail all the checks) there is a lot of merit to using this tool.

Dot NET Coding Guidelines

This is a great document on Dot Net coding guidelines.

XML Documentation Comments Guide

I found a good XML documentation comments guide.

XML Documentation

I am trying to decide on a documentation utility for VB projects and am reviewing the following options;

1. Sandcastle,

2. VBDocMan,

3. Document X,

I have found that sandcastle does not support a jump in and use approach, lacks documentation and support.

I am reviewing VBDocMan and Document X.  Any thoughts drop a comment.  I will update once i have completed my review and made a decision.

Wednesday, April 21, 2010

Great post on vs2010 debugger

Scott Guthrie (@scottgu)
4/21/10 7:47 PM
I just did a blog post that talks about a bunch of small, but really nice, new VS 2010 debugger features:

Logging to a database with nLog

Nlog is a great tool for logging with in VB.Net applications(  This post will discuss setting up nLog to write to both a local log file and a a SQL database.

First, we need to configure the log file;

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns=""
      xmlns:xsi="" internalLogFile="Nlog.log">
        <target name="file" xsi:type="File"   layout="${longdate}|${level}|${callsite}|${logger}|${threadid}|${windows-identity:domain=false}--${message} ${exception:format=message,stacktrace:separator=*"  fileName="c:\psnet\myapplication.log" />
    <target name="database" type="Database">
        Data Source=databaseservername;Initial Catalog=databasename;User Id=username;Password=password;
        insert into system_logging(log_date,log_level,log_logger,log_message,log_machine_name, log_user_name, log_call_site, log_thread, log_exception, log_stacktrace) values(@time_stamp, @level, @logger, @message,@machinename, @user_name, @call_site, @threadid, @log_exception, @stacktrace);
      <parameter name="@time_stamp" layout="${longdate}"/>
      <parameter name="@level" layout="${level}"/>
      <parameter name="@logger" layout="${logger}"/>
      <parameter name="@message" layout="${message}"/>
      <parameter name="@machinename" layout="${machinename}"/>
      <parameter name="@user_name" layout="${windows-identity:domain=true}"/>
      <parameter name="@call_site" layout="${callsite:filename=true}"/>

      <parameter name="@threadid" layout="${threadid}"/>
      <parameter name="@log_exception" layout="${exception}"/>
      <parameter name="@stacktrace" layout="${stacktrace}"/>

        <logger name="*" minlevel="Info" writeTo="file"/>
    <logger name="*" minlevel="Info" appendTo="database"/>

There are a couple fields that need to be configured (in bold).  One adjustment for testing is setting the (internalLogFile="Nlog.log").  This will assist us in debugging any database issues we have as this is nLog’s own log file.

Next, we need to created a matching database table;

/****** Object:  Table [dbo].[system_logging]    Script Date: 04/21/2010 17:05:06 ******/



CREATE TABLE [dbo].[system_logging](
    [system_logging_guid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [entered_date] [datetime] NULL,
    [log_application] [varchar](200) NULL,
    [log_date] [varchar](100) NULL,
    [log_level] [varchar](100) NULL,
    [log_logger] [varchar](8000) NULL,
    [log_message] [varchar](8000) NULL,
    [log_machine_name] [varchar](8000) NULL,
    [log_user_name] [varchar](8000) NULL,
    [log_call_site] [varchar](8000) NULL,
    [log_thread] [varchar](100) NULL,
    [log_exception] [varchar](8000) NULL,
    [log_stacktrace] [varchar](8000) NULL,
    [system_logging_guid] ASC



ALTER TABLE [dbo].[system_logging] ADD  CONSTRAINT [DF_system_logging_system_logging_guid]  DEFAULT (newid()) FOR [system_logging_guid]

ALTER TABLE [dbo].[system_logging] ADD  CONSTRAINT [DF_system_logging_entered_date]  DEFAULT (getdate()) FOR [entered_date]

You must ensure that you give access to this table to the username you provide in the nLog configuration file.

In order to get emailed with error entries simple add this trigger to the system_logging table;

/****** Object:  Trigger [dbo].[LogEmail]    Script Date: 04/21/2010 17:06:42 ******/
-- =============================================
-- Author:        Justin Davis
-- Create date: 4/1/2008
-- Description:    Send email of log message
-- =============================================
ALTER TRIGGER [dbo].[LogEmail]
   ON  [dbo].[system_logging]
   AFTER insert
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    Declare @ToEmail varchar(100)
    Declare @Title varchar(100)
    Declare @logmessage varchar(8000)
    declare    @loglevel as varchar(100)   
    set @ToEmail = 'youremailaddress'
    set @Title = 'Error'
    set @loglevel = (select log_level from inserted)
    set @logmessage = (select
    'User Date:' + char(9) + char(9) + log_date + char(13) + char(10) +
    'Computer:'+ char(9) + log_machine_name + char(13) + char(10) + 
    'User:' + char(9) + char(9) + log_user_name + char(13) + char(10) + 
    'Level:' + char(9)+ log_level + char(13) + char(10) + 
    'Logger:' + char(9)+ log_logger + char(13) + char(10) +
    'Thread:'+ char(9) + log_thread + char(13) + char(10) +   
    'StackTrace:'+ char(9) + log_stacktrace + char(13) + char(10) + 
    'CallSite:'+ char(9) + log_call_site + char(13) + char(10) +
    'Message:' + char(9) + log_message + char(13) + char(10) + 
    'Exception:'+ char(9) + log_exception as 'emailmessage'   
    from inserted)
    if @loglevel <>'Info'
    EXEC msdb.dbo.sp_send_dbmail @recipients=@ToEmail, @body= @logmessage,  @subject = @Title, @profile_name = 'default'


Make sure that you configure SQL mail first.  You might get an exception in the nlog.log file like this;

2010-04-21 13:53:02.0729 Error Target exception: System.Data.SqlClient.SqlException: The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at NLog.Targets.DatabaseTarget.DoAppend(LogEventInfo logEvent)
   at NLog.Targets.DatabaseTarget.Write(LogEventInfo logEvent)
   at NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory)

If so you it is because the username in the nlog.config file does not have access rights to the send mail SP.  Run this script to fix.

EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole'
    ,@membername = 'logger';



VS2010 Migration

Migrating to a new development IDE brings a number of issues when developing line of business applications.  With all the exciting features in VS2010 we still have to consider issues like third party component issues, Net Framework 4 availability on client machines, mixing of development IDE’s (VS2008, VS2010) and many other minor issues.

Im my migration from VS2008 and Source Gear Fortress source control to VS2010 and team foundation 2010 I am making baby steps.  First, I completed a long over due update to my Fortress source control (server and client) that addressed many existing bugs and brought VS2010 support.  Second, I have decided to start using VS2010 for new server based applications where Framework 4 deployment is not as much of an issue. Third, I have delayed adopting team foundation server 2010 until the IDE migration is completed.  This will allow me and my team time to get use to the IDE and test team foundation server.

Over the next few days I will be working on a few production projects using VS2010 targeting both 3.5SP1 and 4 frameworks using Fortress source control to test the waters.  I am also getting use to team foundation server 2010 by running sample applications in VS2010 and using TFS for source control.  This provides a nice test environment that allows me to get use to both VS2010 and TFS without compromising my production environment. 

How to configure Windows Live Writer for Blogger

I started to use Windows Live Writer for posting to my blogger account and was getting this error when I tried to publish.

“The remote server returned an error: (403) Forbidden.”

Here is a great link on how to address the issue;

VS2010 Database Comparison Features

One of the exciting additions to VS2010 are database comparison utilities.  The IDE now supports schema and data comparison.  Having used Adept SQL and Red Gate SQL compare for years it was refreshing to see similar functionality in the IDE.

Accessing the features are simple.  From the main menu select Data. (Figure1)

Figure 1

Schema Compare
The schema compare features allows you to select from the current project or any database connection (figure 2).

Figure 2

While this might now have all the features provided in Adept SQL or Red Gate SQL Compare, it does provide a compelling option.

Data Compare
The data compare feature set is quite good as well. The selection process is similar to schema compare with some additional options (Figure 3).

Figure 3

The comparison window is clean and simple to use.

While it is not a complete replacement for third party comparisons tools many will find the feature set sufficient for there use.

Here is a link to Microsoft documentation on "Comparing Databases" from team services 2005 but provides some details;

Here is a link to a good post on the subject;

Create a Project from Existing Code Files

There are a few scenarios where you may have code files but be missing the project and/or solution file. This is common when downloading sample files from websites like Code Project or other such sites. One of the new features of VS2010 is the ability to create a project/solution file from existing code files. While this is not one of the more glamorous features it is a nice feature that can save some time.

Accessing the feature is simple, however, keep in mind that this does not create a new project/solution by copying the current files into a new project. Rather this feature adds the project/solution files to the folder you select.


Select File, New, Project From Existing Code (figure 1).

Figure 1

Select the project type you want to generate (figure 2)

Figure 2

Select the location of the code files, provide a name for the new project file and select the project output type (figure 3).

Figure 3

While this is not one of the revolutionary feature enhancements in VS2010 it does provide a nice service and one of many functions added to simplify the development process.

Tuesday, April 20, 2010

Source Gear Fortress Upgrade

In my migration to VS2010 I found an issue with my current source control provider version.
I am a current Source Gear Fortress customer and running 1.1.1 without a current support agreement.  I checked the Source Gear website about an upgrade to Fortress 2.0 and found it would run over $3000 for my team to upgrade.  I called and spoke to sales and they informed me of an offer they have until June 15th. 

I have been using them for several years and been really happy. While I am considering moving to TFS (with all the positive changes in TFS2010) I will be using Fortress for a while longer.

If you're a current Source Gear user and cannot switch to TFS right now you should look into this offer.

This is the offer they have for a limited time:

Last week Microsoft announced the release of Visual Studio 2010. For the next 60 days, you can upgrade to Fortress 2.0 for just $149/user.

Why upgrade? Fortress 2.0 fully supports Visual Studio 2010 integration. Even better, $149 is $10 off the usual upgrade price from version 1.1 ($249).

You don't need to be a VS 2010 user to be eligible for the discount. If you've received this e-mail, you can upgrade to Fortress 2.0 for just $149.

There are lots of other great reasons to upgrade, including:

•    New VSS Handoff
•    New Shelve Feature
•    Web Client Redesign
•    Email Settings Improvements
•    WebDAV connections enable cross-platform support for DreamWeaver

It's easy to upgrade. Login to the SourceGear Customer Service Portal [CSP] using the link below to see our product catalog. You'll see an option to purchase a new Fortress 2.0 key for $149 for each license registered under your name:


This offer will expire on June 15, so don't delay.

Want more information first? Our Engineering Manager Jeremy Sheeley highlights some of the great new features of Fortress 2.0 at the Vault blog:


Interested in more information on VS 2010 integration with SourceGear Fortress? Please see this Knowledge Base article:


VS2010 Side-by-Side Installation

Today I installed VS2010 Ultimate side-by-side with VS2008 on my primary development workstation. After sweating it out for about 20 minutes the installation went exterammly smooth. I have worked on several VS2009 solutions and a couple VS2010 test solutions without any issues.

Source Control Issue
I am currently using Source Gear Fortress (version 1.1.1) and debating upgrading to version 2.0.3 which will be a pay upgrade to obtain VS2010 support or moving to Team Foundation Server. I have a heavy investment in Source Gear with a couple repositories and a lot of projects. With the number of members on my team and current workload I don't want to take on the learning curve of a new ALM solution, however, at the same time I don't want to spend a lot of money on an upgrade I might not keep very long as I want to migrate to TFS as soon as I can.
If anyone has any thoughts on Source Gear Fortress 2.0 vs. Team Foundation Server on a team of less than twenty please drop me a note. Also, any thoughts on automating the migrations from source gear to TFS.

Monday, April 19, 2010

Ten Features in Visual Studio 2010 You May Not Know About

Great post from A developers life on some features.

Development Demo Machine Recommendations (Laptop vs. Small Form Factor Workstation)

As part of my discussion on development environment recommendations I wanted to review demo workstation recommendations also. First, the key is virtualization. Unless you have a compelling reason not to virtualize (USB support was an issue with Virtual PC 2007, however, Windows Virtual PC within Windows 7 has great USB support). Second, choosing the right virtualization configuration is a critical decision. There are two main options a laptop or small form factor workstation. While the laptop is the clear choice for portability the unique requirements for virtualization bring some factors into questions beyond portability.

In the virtual environments you need lots of RAM with 4GB being shared between the host and client (2GB each) and a secondary hard drive to the primary host OS drive. While secondary USB hard drives are ok they generally lack the speed to really be effective.  I have found huge variations between drive models even with the same vendor and interface.  A better option is eSata external hard drives and the best are SATA internal drives. Both eSata and secondary internal drive bays on a laptop are reserved for the higher end workstations.

Originally I purchases an Iomega Max Drive 1TB eSata external drive for my virtual machines, however, I have had constant issues with the drive and would not recommend it for VPC. It is a great drive for storing files and the price and speed is good.

While a high end laptop will meet the requirements another option is a small form factor workstation (from Dell’s mini towers, all-in-ones and mini desktop units). These are relatively inexpensive and easy to add additional lower cost desktop Ram and hard drives. A laptop that will work well for this will run around $4000 while a comparable small form factor solution will cost in the $2000 range.

The bottom lines is the laptop solution is the best (when cost is not a factor), however, if your use your primary development workstation as a demo unit you can reduce the overall cost and with the virtual demo machine your note jeopardizing your development environment. You can also have the demo virtual machine on standby for when you need it and it is easy to share. The small form factor is really only an option when cost is a major factor. You can stretch your dollar a lot more with these units, however, you suffer in portability which can be critical if you travel a lot.

I look forward to hearing your thoughts on this topic so be sure to comment…

Sunday, April 18, 2010

Application Logging with nLog

Logging is a vital component of any successful application. Effective logging within any application is a mix of art and science. Over the years I have used a number of logging solutions with mixed results; however, over the last few years I have been using nLog with great success.

Below are some links to nLog resources.

Friday, April 16, 2010

Visual Basic Hardware & Software Configuration Guidance - Introduction

I recently purchased a new development laptop and prior to buying did a great deal of  research on the best hardware and more importantly best software configuration.  First, i was looking for more detail then the fastest CPU, most RAM and biggest 7200 RPM hard drive.  Second, I am committed to Visual Studio 2008/2010, so my questions we more about deployment options such as partitioning between primary and secondary hard drives, to run the IDE in a virtual machine or not and best OS (Server 2008, Windows7) options.

While i found a lot of general suggestions there was little specific guidance.  While i moved on and purchased my replacement development workstation and followed some of the advices i gleamed from the web I was left with the feeling that I cannot be alone in these questions.

So this will be my introductory post in a small series on the hardware and software configuration guidance for visual basic development environments.

To begin I have listed my current hardware for review and will address the decisions behind there purchase as we progress.

Primary workstation
My new primary workstation is aDell Precision m6500 mobile workstation.  It has an i7 CPU, 4GB RAM, 128GB SSD primary drive (factory samsung), a 500GB 7200 RPM secondary drive (data, program files and virtual machines) and have it loaded into a docking station with two 24in Samsung HD monitors.

I don't remove the workstation from the docking station very often.  Rather I connect via remote desktop from my portable laptop, mac or home workstation.

My previous workstation (for about 3 years) was an Alienware m9750.  This was the best workstation available at the time of purchase and I still take it on trips when i need a large screen and a backup development environment.

Portable Laptop
I carry a Dell Mini9 (2GB RAM, 64GB SSD and Verizon USB EVDO wireless card) which I use to connect to the workstation while traveling.  Having been in the IT field for so long I have always been provided hardware by my employers and this was the first laptop I purchased with my own funds.  It came with 1GB of RAM and a 16GB hard drive with WinXP loaded.  I update the memory and hard drive and put WIndows 7 Beta 1 on it and have been very pleased with the performance.

With the exception of my current home workstation (primarily for the family) I have custom built every personnel workstation I have ever owned.  About 2 years ago I was busy working and broke down and bought a Dell Inspiron 530S  slim tower, 2GB RAM, 320GB hard drive, Nvidia Geforce 8200GS (which just died on my yesterday).

I stated really using and carrying smart phones/PDA's when compaq released the IPAQ.  It was a great device for its time.  I have used about every device since then (mostly windows mobile devices) and switched to an iPhone about two years ago.  Sometimes I miss tweaking with the PocketPC/Windows Mobile platform, however, the iPhone just works.  There are a lot of things I would change but It does a good job at calls, email, SMS, web and other applications.  

I do miss being able to develop for the device.  Recently I was forced to purchase a MAC (MacBook) to address some Silverlight issues on workstations running MAC/Safari and in the process have downloaded and started to review the iPhone development platform.  So expect to see some posts on that endeavor in the near future.

While now that full discloser on my current hardware status is documented we can move on to my current software configuration.  Then on to discussing better informed decisions on these topics.

Until next time...

Team Foundation Server Blog

This is a good blog related to Team Foundation Server.

"Dogfooding" VS 2010 and .NET 4

Great blog on visual studio and .net 4 framework.

Silverlight 4 Released!

Great blog post from Scott Gu on the release of Silverlight 4 RTM

Visual Studio 2010 and .NET 4 Released

This is a great link to Scott Gu's blog about the release of visual studio 2010 and .Net 4 framework RTM.

Microsoft SharedView is a great desktop sharing tool that is free. This allows you to share your desktop with other users dor demos and support issues. also offers a good "file in the cloud" feature set. Not as much free space but they have windows (mapped drive support mapping to, browser and mobile browser and IPhone support.

check it out

Dropbox is a great tool for keeping files avaiable across multiple devices (windows, mac and iphone)  in sync automatically and is free (2GB limit, more with payed account).  I have been using it for about three weeks and really like it.

Try it out here
Here is a great poster that displays all the default keybindings in Visual Basic.

This is a link to the Microsoft Visual Basic Default Keyboard mapping (VB IDE shortcuts) on google docs. Link
Installing Visual Studio 2010 Ultimate on the same virtual machine as the TFS.  I am pleased how good the performance is on the VM.  I am running a Dell m6500 with 4GB ram running Windows7.  The primary hard drive is a SSD drive with data and VM on secondary internal eSata drive.
Just compelted installation of Team Foundation Server 2010 on a virtual machine.  I changed the server name after installing SQL server and reporting services which caused reporting services to stop working (had to configure database server name in reporting services configuration manager) and that was the only issue I during the installation. 

Next step create project for testing...
Deploying team foundation server 2010 on virtual machine.