Step 1: you need to find out your SQL Server's data directory. This will be something like
C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data
by default (for SQL Server 2008 R2 Express) - it might be slightly different in your case, depending on how you installed your SQL Server Express (and which version you have).
Step 2: copy that record.mdf
file to that directory
Step 3: attach it to your SQL Server Express instance - using sqlcmd
if you don't have Mgmt Studio at hand:
c:\> sqlcmd -S .\SQLExpress
Then at the sqlcmd prompt, type in:
USE [master]
GO
CREATE DATABASE record ON
(FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\record.mdf' )
FOR ATTACH_REBUILD_LOG;
GO
This will attach the .mdf
file as your new "logical" database record
to your SQL Server Express instance, and it will rebuild the missing transaction log file (.ldf
) in the process.
From now on, you can use
server=.\SQLEXPRESS;Database=record;Integrated Security=SSPI;
as your connection string to connect to your database