Question

Background: I have both SQL2008 and SQL2012 installed on my machine. This has resulted in only having the studio management for 2012 running, and any amount of trying wont let me add the studio for 2008.

Problem: Now I have backup that for verification reasons need to be restored on the 2008 instance without the 2012 management studio to avoid contamination, so I am trying to run the restore directly from the command prompt. I have let the 2012 studio make the actual command for me, and am now trying to put that into the prompt, but it won't run; and no amount of reading makes me see the invalid argument. I realize I am probably missing something elemental, but please have a look at it anyway.

The command that I am trying to run is:

C:\Program Files\Microsoft SQL Server\100\Tools\Binn>SqlCmd -E -S SQL2008 "RESTORE DATABASE Basename FROM  DISK = N'D:\Folder\Backup.BAK' WITH  FILE = 1,  MOVE N'Base_Data' TO N'C:\Folder\Base.mdf',  MOVE N'Base_1_Data' TO N'C:\Folder\Base_1.ndf',  MOVE N'Base_2_Data' TO N'C:\Folder\Base_2.ndf',  MOVE N'Base_Log' TO N'C:\Folder\Base_3.LDF',  NOUNLOAD,  STATS = 5"

And the response is a quick: Unexpected argument. Enter '-?' for help.

I don't see how -E or -S could be wrong, and the server is correct 2008 instance. I have tried it without the MOVEs to see if there could be something there, but it gave the same result.

So could someone please swing a 2 by 4 my way letting me know what I am doing wrong? Thank you

Was it helpful?

Solution

Maybe like this?

C:\Program Files\Microsoft SQL Server\100\Tools\Binn>SqlCmd -E -S SQL2008 -Q "RESTORE DATABASE Basename FROM  DISK = N'D:\Folder\Backup.BAK' WITH  FILE = 1,  MOVE N'Base_Data' TO N'C:\Folder\Base.mdf',  MOVE N'Base_1_Data' TO N'C:\Folder\Base_1.ndf',  MOVE N'Base_2_Data' TO N'C:\Folder\Base_2.ndf',  MOVE N'Base_Log' TO N'C:\Folder\Base_3.LDF',  NOUNLOAD,  STATS = 5"

OTHER TIPS

It seems like the most common issue with this problem is copying and pasting from some other source, as mentioned in the comments in the other answer. My problem was copying and pasting from this article:

http://www.howtogeek.com/50295/backup-your-sql-server-database-from-the-command-line/

To fix this, try typing your command in manually so you know the exact value of every character. Usually the problem characters are double quotes, but they can also be single quotes, and my problem was in fact the dash character being U-2014, the "EN DASH". Even the spaces could potentially be nonblocking spaces i suppose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top