Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 xp_cmdshell copy command error

Author  Topic 

assh11
Starting Member

7 Posts

Posted - 2010-04-25 : 19:14:24
Hi All,

In the query analyzer I am giving the following command.

exec master.dbo.xp_cmdshell 'copy d:\Program Files\Microsoft SQL Server\MSSQL\Data\MyDatabase_Data.MDF c:'

I am getting the following error:
1. The system can not find the path specified
2. NULL

What is the problem with the command? If anyone knows please let me know. Your help is greatly appreciated.

Thank you,
Assh

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-25 : 19:16:44
1. You can only move the file if the SQL Server service is stopped.
2. Don't you need c:\ at the end?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-25 : 19:25:14
It's a catch-22 case here. You are trying to move the data file, but the service isn't stopped. You can't run xp_cmdshell unless the service is started.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

assh11
Starting Member

7 Posts

Posted - 2010-04-25 : 19:55:16
Hi,

It is working now. The problem is with the source file path because it has many spaces in it. The correct command is

exec master.dbo.xp_cmdshell 'copy d:\Program" "Files\Microsoft" "SQL" "Server\MSSQL\Data\MyDatabase_Data.MDF c:\MyDatabase_Data.MDF'

we need to add double quotes in place of spaces.

Thank you,
Assh
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-25 : 20:09:14
I am shocked that SQL Server allowed you to move the file. You may have corruption now if the service wasn't stopped or the database wasn't detached.

Also, you don't need to put the double quotes in the string so many times. You just surround it with them, but if it works then great.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-25 : 20:11:36
Based upon your other topic (which I had forgotten since I respond to many posts per day), you are detaching the database. Make sure you run DBCC CHECKDB after the attach each time to ensure there is no data corruption.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -