Reputation: 1975
I have downloaded a sql server .mdf and .ldf file from web and when I try to attach it with my sql server 2014 (Using Management Studio) I am getting the below error.
Attach database filed for server 'MyServer\SQLEXPRESS'. (Microsoft.SqlServer.Smo)
Additional Information An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Directory lookup for the file "C:\Leave Management\App_Data\Leave.mdf" failed with the operating system error 3 (The system cannot find the path specified.) (Microsoft SQL Server, Error: 5133)
Any suggestion about what I am doing wrong and how to handle this error?
I kept the database file in C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA
Script I received while attaching the file
USE [master]
GO
CREATE DATABASE [C:\LEAVE MANAGEMENT\APP_DATA\LEAVE.MDF] ON
( FILENAME = N'C:\Leave Management\App_Data\Leave.mdf' ),
( FILENAME = N'C:\Leave Management\App_Data\Leave_log.LDF' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA' )
FOR ATTACH
GO
Upvotes: 0
Views: 7079
Reputation: 9391
If you have the files in the SQL DATA directory try executing this script:
CREATE DATABASE [LEAVE] ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\Leave.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\Leave_log.LDF' )
FOR ATTACH
Upvotes: 4