When my code is in tons of trouble…Write in C

When I started programming as a career, I did so in VB.NET. It was my preferred language of choice and I never thought of trying C#. When I changed jobs back in 2007, I forced myself to take a leap of faith and use C# exclusively. (more…)

Continue ReadingWhen my code is in tons of trouble…Write in C

Exporting SQL Query Results to a CSV file using SQLCMD and C#

Today a colleague asked me how to export SQL Query Results to a CSV file. This got me thinking that it would be a nice exercise to do this from a C# application. So to start off, I downloaded the correct AdventureWorks database for my version of SQL from the…

Continue ReadingExporting SQL Query Results to a CSV file using SQLCMD and C#

C# Programming – Caller Information Attributes

Okay, so I don’t have a specific series for this and seeing as this is more of a programming tip, I’ll leave it out of the Visual Studio 2012 Tips series. Caller Information Attributes are a very useful and probably underutilized feature implemented in the C#5.0 Compiler. Caller Information Attributes allow you to see how  your method was called. So forget having to sift through the stack trace in order to achieve diagnostic level logging, use Caller Information Attributes instead. (more…)

Continue ReadingC# Programming – Caller Information Attributes

Debugging Windows Services using an #if Directive

Debugging Windows Services – I love writing them. In fact, to encompass a unit of functionality in a self contained bit of code is incredibly powerful. That is, if it is written correctly. I think it is something we as programmers take a bit for granted. One thing I know, is that debugging a Windows Service is one of the most painful things ever. Give it a try… Create a Windows Service in Visual Studio (I’m using Visual Studio Ultimate 2012), start it in debug mode and take a gander at the error message you get.

(more…)

Continue ReadingDebugging Windows Services using an #if Directive

Creating a Windows Service with a Timer

Okay, you probably all know this, but somewhere someone doesn’t. And I thought it might be a nice article to post. Have you created a Windows Service Timer that isn’t working? The reason for this is because you probably added a Windows Forms Timer to your Service instead of a System Timer. So for future reference, this is what I did:

(more…)

Continue ReadingCreating a Windows Service with a Timer