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.

Resharper File template for Nunit testing with Structuremap support for VB.Net

So I also made the a similar template with structuremap support included. Which looks something like this Imports Nunit.FrameWork Imports StructureMap Namespace $NAMESPACE$ ''' <summary> ''' A TestClass ''' </summary> ''' <remarks></remarks> <TestFixture()> _ Public Class $CLASSNAME$ #Region " Setup and TearDown " ''' <summary> ''' Sets up the Tests ''' </summary> ''' <remarks></remarks> <Setup()> _ Public Sub Setup() StructureMapConfiguration.UseDefaultStructureMapConfigFile = False StructureMapConfiguration.ScanAssemblies.IncludeTheCallingAssembly() End Sub ''' <summary> ''' Tears down the test. Is executed after the Test is Completed ''' </summary> ''' <remarks></remarks> <TearDown()> _ Public Sub TearDown() ObjectFactory.ResetDefaults() End Sub #End Region #Region " Tests " ''' <summary> ''' A Test ''' </summary> ''' <remarks></remarks> <Test()> _ Public Sub $Test_Name$() End Sub #End Region End Class End Namespace``` And of course I also made an XmlFile so you can easily import it. [NunitTestFixtureWithStructureMapSupport.xml][1] [1]: http://blog.baesonline.com/content/binary/NunitTestFixtureWithStructureMapSupport.xml

Read More...

Find the last Backup taken in SQL Server

SELECT * FROM msdb.dbo.backupmediafamily backupmediafamily JOIN msdb.dbo.backupset backupset ON backupmediafamily.media_set_id = backupset.media_set_id and backupset.backup_start_date = (SELECT max(backup_start_date) FROM msdb.dbo.backupset child WHERE child.database_name = backupset.database_name and child.type = 'D') and database_name = 'ReplaceWithDatabaseNameHere' and backupset.type = 'D'``` This is based on something I found here. Thank you mrdenny. And this works in SQL Server 2000.

Read More...

Do automated restore tests on your SQL-Backups.

I found out yesterday that my SQL server backups were corrupt and so I couldn’t restore them (happy me). So I went out on Google and combined a few things to make this declare @verifystatement nvarchar(250) declare @backupdevice nvarchar(250) declare @err int set @backupdevice = (SELECT TOP 1 [physical_device_name] FROM msdb.dbo.backupmediafamily backupmediafamily JOIN msdb.dbo.backupset backupset ON backupmediafamily.media_set_id = backupset.media_set_id and backupset.backup_start_date = ( SELECT max(backup_start_date) FROM msdb.dbo.backupset child WHERE child.database_name = backupset.database_name and child.type = 'D') and database_name = 'TexDatabase' and backupset.type = 'D') set @verifystatement = 'restore verifyonly from disk = ''' + @backupdevice + '''' exec sp_executesql @verifystatement SELECT @err = @@error if @err <> 0 begin insert into utils.dbo.tbl_backupverify(BackupDevice,BackupStatus,BackupError, VerifyStatement) values (@backupdevice, 'Failed', @err, @verifystatement) end else begin insert into utils.dbo.tbl_backupverify(BackupDevice,BackupStatus) values (@backupdevice, 'Succes') end``` Just put it in a Store procedure and run it as a job. This is the tbl_BackupVerify create table statement. if exists (select * from dbo.sysobjects where id = object_id(N’[dbo].[tbl_BackupVerify]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1) drop table [dbo].[tbl_BackupVerify] GO```

Read More...

File unlocker for windows

On windows files can be locked by different programs. This little gem unlocks your file so that you can delete it.

Read More...

Simple addition of a range

Adding a range of numbers Adding numbers is easy. Very easy for programs, right? How about adding up a range of numbers? 1 to 5 maybe ? 1+2+3+4+5 = 15 … easy ! What about adding up 1 to 100 ? not so easy in your head, but with a little code this shouldn’t be a problem. In fact a lot of programmers would approach it like the following: var sumOfRangeLoop = 0; for (i=1;i<=100;i++) { sumOfRangeLoop += i; } document.write("Loop: " + sumOfRangeLoop + "<br/>"); Great – it gets you the answer that you wanted. Now what about 25 to 25,000,000 ? OK, that takes a while to run…. What if I tried 234 to 435,657,123 ? Mmmm… ouch. This doesn’t work too well does it ?

Read More...

Listen to yourself

Well :oops:, I can still hear myself say to everybody who wanted to hear it “Keep the objects that you are returning in your webservices simple”. So this means, don’t return complex objects like a dataset, datatable, arraylist or all other kinds of collections. Make a POCO (Plain old C# object) and pass that to the client. So yesterday I switched to VS 2008 and the first thing I do is compile the thing and get the application out there. And guess what, one of my webservices started returning gibberish. So after a while I noticed that this webservice (not written by me) returned an Arraylist and although I didn’t write the webservice myself I should have checked before deploying. I changed the ArrayList to a simple array of objects and hey presto, everything worked again. Happy me.

Read More...

VS 2008 ErrorMessage

Yesterday I finally installed VS2008 at work. And it was apart from the time spent pretty painless. Adapting finalbuilder turned out to be a little less painless but that is another story. So I was surprised today that the some of the bugs are still there bu that the errorscreen has gotten an upgrade. So if you can’t make it better then make the errors nicer to look at.

Read More...

Review of Inside Microsoft SQL Server 2005 Query Tuning and Optimization

SQL performance tuning is probably one of those things you can do to really make a HUGE difference in performance. Let’s put this in perspective: take a typical application, if you can improve the performance by 100% then you really made a huge improvement. You can improve a SQL query by 1000% with 2 lines of code (sometimes all you have to do is take away a % sign). If you can make a query sargable so that the optimizer can do an index seek instead of an index scan your query might go from 12 seconds to 200 milliseconds. Now try doing that in an application, even if you change all the string concatenation to use a stringbuilder instead of creating new strings all the time you will not get such a drastic performance improvement. I am sure you get the point by now, let’s talk about the book.

Read More...

The concepts of OOP

My explanation Well there seems to be some confusing opinions on the net over what OOP seems to be. I’ve been reading up on the concepts of OOP after a little discussion with our teacher yesterday where he did most of the talking. He followed the APIE principal A = Abstraction P = Polymorphism I = Inheritance E = Encapsulation 1. Abstraction Not many sites talk about this concept as part of OOP but apparantly this means that abstract real world things to your code, for example Car, Vehicule, Sportscar, … become objects. So you try to mimic Real world objects into an OO model.

Read More...