Skip to content

MikeBevers.be

Putting it out there…

Problem

Lately I’ve been listening to some MP3 songs on my corporate laptop. Today I noticed that the library of Windows Media Player (WM Player) was getting pretty big. I don’t want my corporate laptop to contain a lot of information about my music. So I was looking for a “clear” button or menu item but didn’t find any. Because I don’t usually use WM Player as an MP3 player, I don’t really know all the features and options. Let’s go and take a look.

Quick solution

If you want to delete the entries in the library, close your WM player and navigate to “C:\Documents and Settings\YourUserNameGoesHere\Local Settings\Application Data\Microsoft\Media Player”. Found it? Close your WM Player. Now delete all the files in the folder! Restart WM Player and you’ll see that the library is empty.

continue reading…

Context

Unfortunately, there is no easy way to create a fully qualified XML file. The problem is that a rolling file appender writes its entries sequentially. As we all know, an XML file has to start with opening a root element and end with closing the root element.

Of course, we can always provide some kind of workaround.

continue reading…

Context

I wanted log4net to write its log entries in a SQL Server database. log4net’s AdoNetAppender would have done the trick. But, there are three requirements I need to keep in mind.

  1. I have to use my logging framework
  2. The connectionstring has to be stored the app.config or web.config
  3. The machine’s hostname has to be added to the log entry

continue reading…

What is log4net

If you have never heard about log4net, this article isn’t immediately suited for you. Dimitri Clement wrote a few articles about log4net and how to use it:

You can also visit the log4net website.

continue reading…

Context

Every developer knows that managing your app.config or web.config isn’t an enjoyable task. When you’re moving your application from one environment to another, you will need to change some variables. Maybe you’re working with automatic builds, and so on.

Since Visual Studio 2010 you have a new feature: “Config transformations”. Because I’m still working with Visual Studio 2008, I can’t use it. That’s why I wrote my own config transformer.

continue reading…

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

Context

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

Context

I’m not a big fan of handling exceptions in stored procedures. It means that you have complicated queries, thus have some business logic in them. Although I like to keep my logic in code, sometimes it’s necessary to have some logic in your stored procedure.

Usually, I only use it to increase performance.

continue reading…

The Problem

I generally like using the IDE’s that Microsoft provide for developers. But in this case, I had an annoying problem. When creating my database model I always use Microsoft SQL Server Management Studio. As you all know, during development your tables often change a bit. You create new columns, delete old ones, change the type of a column, define new keys, etc.

In SQL Server 2005 SSMS I don’t remember doing one of the above actions resulted in an error. Now I’m using SQL Server 2008 SSMS and I repeatedly got the error: “Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created”.

continue reading…