LessThanDot Site Logo

LessThanDot

A decade of helpful technical content

This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.

How to Rebuild System Databases in SQL Server 2008

The PSS SQL Server Engineers made a nice blogpost explaining How to Rebuild System Databases in SQL Server 2008 In SQL Server 2005, we introduced a different method than in previous versions to rebuild system databases (affectionately known as “rebuild master”). You were required to use the setup.exe program with command line switches. This is no different in SQL Server 2008 but the command line switches have changed some and the process behind the scenes to rebuild the system databases (master, model, and msdb) is also a bit different.

Read More...

VB.Net: Check if an Event Gets Raised By a Method

Let’s say we want to test to see if our object really throws that event when we need it to. Public Class EventThrower Public Event throwme(byval somestring as String) Public Sub SomeSub() RaiseEvent throwme("Yeepie!") End Sub End Class So when calling a method SomeSub an event throwme will be raised. Now we make a little unittest class that looks like this. Imports NUnit.Framework Imports Rhino.Mocks <TestFixture()> _ Public Class TestEvent #Region " Private members " Private _Mocker As MockRepository #End Region #Region " Setup and TearDown " <Setup()> _ Public Sub Setup() _Mocker = New MockRepository End Sub <TearDown()> _ Public Sub TearDown() _Mocker.

Read More...

LINQ to SQL queries involving strings cause SQL Server procedure cache bloat

Adam Machanic created an item on connect explaining how LINQ to SQL queries involving strings cause SQL Server procedure cache bloat If an application is using LINQ to SQL and the queries involve the use of strings that can be highly variable in length, the SQL Server procedure cache will become bloated with one version of the query for every possible string length. For example, consider the following very simple queries created against the Person.

Read More...

VB.Net and Resharper and the Property generation thing

In my last blogpost I talked about property generation and how the naming for the generated property seemed a bit strange. Luckily the guys from JetBrains (Ilya Ryzhenkov) read our blog 😉 and gave a comment. So I acted on it and found what he was talking about. I always use the prefix with underscore and have camelcasing because I have NHibernate setup like that too. And it becomes a habit.

Read More...

SQL Server 2008 Express with Advanced Services And SQL Server 2008 Express With Tools Now Available For Download

There are 3 versions of SQL Server 2008 Express now available for download from the SQL Server 2008 Express site. Below are the 3 different versions SQL Server 2008 Express SQL Server database engine – create, store, update and retrieve your data SQL Server 2008 Express with Tools SQL Server database engine – create, store, update and retrieve your data SQL Server Management Studio Basic – visual database management tool for creating, editing and managing databases SQL Server 2008 Express with Advanced Services

Read More...

Let Resharper do the heavy lifting for you.

Reshaper is a cool tool that can save you plenty of time (unless you start blogging about it of course ;-)) I will give the examples in VB.Net but this will also work in C#. We all know what a DomainEntity looks like, right? Ok so here is a simple example. Public Class person Private _id As Guid Private _name As String End Class``` First thing to do is create properties for it.

Read More...

How Do You Check If A Temporary Table Exists In SQL Server

I see more and more people asking how to check if a temporary table exists. How do you check if a temp table exists? You can use IF OBJECT_ID(‘tempdb..#temp’) IS NOT NULL Let’s see how it works --Create table USE Norhtwind GO CREATE TABLE #temp(id INT) --Check if it exists IF OBJECT_ID('tempdb..#temp') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --Another way to check with an undocumented optional second parameter IF OBJECT_ID('tempdb.

Read More...

.Net has a Set implementation since the 3.5 framework. Use it.

In Java, they have had a set implementation for ages. Well, .Net has it too. So no more need to import Iesi.set. The HashSet<T> or HashSet(Of T) is one of the collections you need most. For this to work, your objects need to override the Equals and GetHashCode functions, so that they reflect the business rules. I have an example here of a List: Module Module1 Sub Main() Dim personlist As List(Of Person) = New List(Of Person)() Dim person1 As Person = New Person("Chris", "Baes") Dim person2 As Person = New Person("Chris", "Baes") Console.

Read More...

VB.Net: Using PostSharp and Log4PostSharp

After reading an article on the codeproject about PostSharp and Log4Net. So I tried to replicate that in VB.Net and hit a bump in the road. But here is how it got solved in the end. So like the instructions say I downloaded PostSharp and installed it. I also downloaded the log4postsharp sourcecode. Then I created a consoleapplication. I set the references Log4PostSharp.dll and PostSharp.Public.dll (you can find this library on the “.

Read More...

Only In A Database Can You Get 1000% + Improvement By Changing A Few Lines Of Code

Take a look at this query. select * from ( select customer_id, 'MTD' as record_type, count(*), sum(...), avg(...) from payment_table where year(payment_dt) = year(getDate()) and month(payment_dt) = month(getDate()) group by customer_id) MTD_payments UNION ALL ( select customer_id, 'YTD' as record_type, count(*), sum(...), avg(...) from payment_table where where year(payment_dt) = year(getDate()) group by customer_id) YTD_payments UNION ALL ( select customer_id, 'LTD' as record_type, count(*), sum(...), avg(...) from payment_table) LTD_payments ) payments_report order by customer_id, record_type Can you see the problem?

Read More...