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.
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.
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.ReplayAll() _Mocker.VerifyAll() End Sub #End Region #Region " Tests " <Test()> _ Public Sub Test_NewFile_If_RaisesEvent_NewFileMade() Dim subscriber As ISubscriber = _Mocker.DynamicMock(Of ISubscriber)() Dim _EventThrower As New EventThrower AddHandler _EventThrower.throwme, AddressOf subscriber.throwmesub subscriber.throwmesub(Nothing) LastCall.IgnoreArguments() _Mocker.ReplayAll() _EventThrower.SomeSub() End Sub #End Region Public Interface ISubscriber Sub throwmesub(ByVal somestring As String) End Interface End Class End Namespace Just a few notes. I created an interface just for this test. And interface with a method with the same signature as the event. Then in the Test, I subscribe the event to that method. I didn’t forget to set IgnoreArguments and I called the Method on our object.
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.AddressTypes table in the AdventureWorks2008 database:
In my [last blogpost][1] I talked about property generation and how the naming for the generated property seemed a bit strange. Luckily the guys from [JetBrains][2] ([Ilya Ryzhenkov][3]) read our blog 😉 and gave a [comment][4]. 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. So I just had to add the underscore to the namingstyle, like shown in the picture.
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
[Reshaper][1] 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. For this we use the [Reshaper][1] generate option, which is available via the shortcut **Alt+Ins** or via the menu **Resharper->Generate**. This brings up the following contextmenu: <div class="image_block"> <img src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/blogs/DesktopDev/ResharperGenerate.jpg" alt="" title="" width="315" height="270" /> </div> We choose Read-only properties: <div class="image_block"> <img src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/blogs/DesktopDev/ResharperGeneratereadonlyproperties.jpg" alt="" title="" width="501" height="499" /> </div> And get this as a result: ```vbnet Public Class person Private _id As Guid Overridable Public ReadOnly Property _idProperty() As Guid Get Return _id End Get End Property Private _name As String End Class Not ideal, but a timesaver none the less.
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..#temp','u') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --Don't do this because this checks the local DB and will return does not exist IF OBJECT_ID('tempdb..#temp','local') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --unless you do something like this USE tempdb GO --Now it exists again IF OBJECT_ID('tempdb..#temp','local') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --let's go back to Norhtwind again USE Norhtwind GO --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 now open a new window from Query Analyzer (CTRL + N) and run this code again
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.WriteLine(person1.Equals(person2)) Dim person3 As Person = New Person("Chris1", "Baes") Console.WriteLine(person3.Equals(person2)) personlist.Add(person1) Console.WriteLine(personlist.Count) personlist.Add(person2) Console.WriteLine(personlist.Count) personlist.Add(person3) Console.WriteLine(personlist.Count) Console.ReadLine() End Sub Public Class Person Implements IComparable Private _firstName As String Private _lastName As String Public Sub New(ByVal FirstName As String, ByVal LastName As String) _firstName = FirstName _lastName = LastName End Sub Public Property FirstName() As String Get Return _firstName End Get Set(ByVal value As String) _firstName = value End Set End Property Public Property LastName() As String Get Return _lastName End Get Set(ByVal value As String) _lastName = value End Set End Property Public Overrides Function Equals(ByVal obj As Object) As Boolean Return obj.FirstName.Equals(Me.FirstName) End Function Public Overrides Function GetHashCode() As Integer Return Me.FirstName.GetHashCode() End Function Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo obj.FirstName.compareto(Me.FirstName) End Function End Class End Module And the C# implementation:
After reading an [article on the codeproject][1] 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][2] and installed it. I also downloaded the [log4postsharp sourcecode][3]. Then I created a consoleapplication. I set the references Log4PostSharp.dll and PostSharp.Public.dll (you can find this library on the “.NET” tab of the “Add reference…” dialog). And a reference to the log4net dll.
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? A person had this query, it would run for over 24 hours. Wow, that is pretty bad, I don’t think I had ever written something that ran over an hour, and the ones I did were mostly defragmentation and update statistics jobs.