January 12, 2022 at 5:38 pm
Can I attach DB in another server on different drive??
For Example Server: AAA , Database Name: DB_1 the MDF and LDF file is located on C drive
Now I want this data file to copy on another Server: BBB on D drive and than attach the DB.
How Can I do this?? It didn't allow me to attach on D drive and it does allow me to attach from C drive.
January 12, 2022 at 7:29 pm
USE [master];
GO
CREATE DATABASE YourDB
ON
(FILENAME = N'D:\YourPath\DB_1.mdf')
,(FILENAME = N'D:\YourPath\DB_1.ldf')
FOR ATTACH;
GO
January 12, 2022 at 7:52 pm
This is not working
January 12, 2022 at 8:54 pm
Please post error messages for what is not working.
More than likely you have not given permissions to the service account to the location needed.
January 12, 2022 at 9:55 pm
I am trying to copy MDF and LDF file from one server to another.
Initial On primary the DB was on C drive and on new server I was trying to attach on D drive
January 13, 2022 at 12:09 am
I am trying to copy MDF and LDF file from one server to another.
Initial On primary the DB was on C drive and on new server I was trying to attach on D drive
You never posted the requested error messages. You DO realize that you need to change the words "YourPath" and the names of the files and the name of the DB to attach in the correct example that Ken McKelvey posted, yes?
--Jeff Moden
Change is inevitable... Change for the better is not.
January 13, 2022 at 7:29 am
also keep in mind, the SQLServer service account needs to be granted usage of the given paths !
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
January 13, 2022 at 2:27 pm
This is what the error I got
USE [master]
GO
CREATE DATABASE [DBTest] ON
( FILENAME = N'D:\SQL_Data\DBTest.mdf' ),
( FILENAME = N'D:\SQL_Log\DBTest.ldf' )
FOR ATTACH
GO
ERROR Message: (Though I have full access to d drive and I can create any other DB on D drive)
Msg 5120, Level 16, State 101, Line 3
Unable to open the physical file "D:\SQL_Data\DBTest.mdf". Operating system error 5: "5(Access is denied.)".
Msg 1802, Level 16, State 7, Line 3
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
January 13, 2022 at 3:16 pm
As others have already mentioned, it is the SQL Server service account that needs permission to that folder.
Permissions aren't always inherited from the parent -- sometimes they get changed from the parent folder. Just because permissions exist on D: doesn't mean they are granted on D:\SQL_Data... or the individual files in D:\SQL_Data.
I'm assuming you have already copied the files to that folder.
January 13, 2022 at 3:50 pm
To clarify the issue, you, or your account, is not attaching the database on the instance. You are requesting the SQL Server Database Engine do the attach. The database service, which is running under a service account, is what needs permissions.
The post above checks for the default service accounts, but it's possible some other account is being used. You would check this under the Services applet in Windows.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply