Skip to content

Putting it out there…


Archive for August, 2010

Announcement: “CLR via C#” blog series

A friend and colleague of mine and I decided to give several knowledge sharing sessions based on the book: “CLR via C#” by Jeffrey Richter. More info about the book at Microsoft Learning.

We believe it is a very good book, but hard to process. It’s not something you call “light reading”. That’s why we like to redeliver the book to the MSCoP group of Capgemini. Of course, we won’t forget our blog readers! We’ll put all our materials (slides and code samples) online.

We’ve limited our delivery to 4 sessions, one per month. Because we cannot cover the whole book in our sessions, we decided to occasionally blog about the remaining parts of the book.

Session Agenda

Session 1 (End of September)

  • Chapter 1: CLR Execution Model
  • Chapter 2: Building, Packaging, Deploying, and Administering Applications and Types

Session 2 (End of October)

  • Chapter 21: CLR Hosting and AppDomains
  • Chapter 3: Shared Assemblies and Strongly Named Assemblies
  • Chapter 22: Assembly Loading and Reflection

Session 3 (TBA)

  • Chapter 19: Exceptions
  • Chapter 23: Performing Asynchronous Operations
  • Chapter 24: Thread Synchronization

Session 4 (TBA)

  • Chapter 20: Garbage Collection

The problem

Today I wrote some tests for a project I’m working on, which uses the FileHelpers library.

When I tried to run the tests, I received the following error:

Failed to queue test run ‘mbev@WSXP-BE-6833 2010-08-31 11:51:43′: Test Run deployment issue: The location of the file or directory ‘c:\pathToProject\business.tests\bin\debug\FileHelpers.dll’ is not trusted.

First thing that went through my mind was: “Man, I’m trying to introduce testing in this environment and then I get this. Why is everything working against me?!!”. Nevertheless, I put my personal issues aside and worked on resolving the problem.

In the past I’ve encountered a similar issue, but then I was working with network shares. Visual Studio has trust issues with other machines then your own. It that were the case, you can resolve it using CASPOL (Code Access Security Policy Tool). But I’m working on my own machine, on a local drive, my system drive!

The Solution

Suddenly, I remembered that Windows also has trust issues with external dll’s and exe’s. The solution is extremely simple! You can resolve it by clicking two buttons: Unblock and OK…

Restart Visual studio and you’re good to go!

Filehelpers Properties - Blocked


Working with DateTime fields in MSSQL is not the same as you do in .NET. I found myself googling the same things over and over. That’s why I decided to group the things I need most in one blogpost. This way I don’t have to keep googling, I just need to browse my blog and voilà.

I will update this blogpost when I’m in need of different functionalities.

Comparing the date part of DateTime fields

You shouldn’t cast or convert your DateTime fields to text and then do a text compare like:

SELECT CASE WHEN CONVERT(varchar(10), getdate(), 101) = CONVERT(varchar(10), getdate(), 101) THEN 'Equal' ELSE 'Different' END AS 'Compare result'

You should use the DateTime methods provided by Microsoft:

SELECT CASE WHEN DATEDIFF(d, getdate(), getdate()) = 0 THEN 'Equal' ELSE 'Different' END AS 'Compare result'

The DATEDIFF method accepts a datepart argument. The method will base its result on the supplied datepart argument. More info: DATEDIFF on MSDN

Displaying DateTime fields

I found this example on the internet:

SELECT DATEADD(dd, -DATEDIFF(dd, getdate(), 1), 1) -- 2010-08-02 00:00:00.000

I don’t find it very useful to put this in a SELECT statement, maybe when you’re using subqueries to be sure it will be parsed as a DateTime. Again, use the provided methods. In this case it would be the Convert. It’s always nice to see an example result, so here it goes:

SELECT CONVERT(varchar(50), getdate(), 100) -- Aug  2 2010 10:40AM
SELECT CONVERT(varchar(50), getdate(), 101) -- 08/02/2010
SELECT CONVERT(varchar(50), getdate(), 102) -- 2010.08.02
SELECT CONVERT(varchar(50), getdate(), 103) -- 02/08/2010
SELECT CONVERT(varchar(50), getdate(), 104) -- 02.08.2010
SELECT CONVERT(varchar(50), getdate(), 105) -- 02-08-2010
SELECT CONVERT(varchar(50), getdate(), 106) -- 02 Aug 2010
SELECT CONVERT(varchar(50), getdate(), 107) -- Aug 02, 2010
SELECT CONVERT(varchar(50), getdate(), 108) -- 10:40:10
SELECT CONVERT(varchar(50), getdate(), 109) -- Aug  2 2010 10:40:10:870AM
SELECT CONVERT(varchar(50), getdate(), 110) -- 08-02-2010
SELECT CONVERT(varchar(50), getdate(), 111) -- 2010/08/02
SELECT CONVERT(varchar(50), getdate(), 112) -- 20100802
SELECT CONVERT(varchar(50), getdate(), 113) -- 02 Aug 2010 10:40:10:870
SELECT CONVERT(varchar(50), getdate(), 114) -- 10:40:10:870