Category Archives: MS SQL Server

Set Date Back Twelve Hours – MSSQL

Hey everyone,

A quick post on how to set a date value for twelve hours ago using SQL Server:

SET MyDate = dateadd(HOUR, -12, CURRENT_TIMESTAMP)

Simply use the dateadd function and specify the unit (hours in this case). The example above will set MyDate to twelve hours ago.

Here’s the offical documentation on the function:

Also, thanks to this stackoverflow post for the info:


Cannot attach the file ‘C:…database.mdf’ as database x – Entity Framework

Hi everyone,

I ran into the following error when attempting to run ‘update-database’ on an initial migration:

Cannot attach the file ‘C:Users…App_Dataaspnet-…115933.mdf’ as database ‘aspnet-…15933’

The solution to this one is pretty easy, remove the initial catalog property from your connection string.

…33.mdf;Initial Catalog=aspnet…

This is apparently caused by issues with EntityFramework and multiple projects in the same database. See the following stackoverflow answer for more info: