Question

sqlcmd -S servername\sqldeveloper -E "EXEC sp_BackupDatabases @databaseName=’myDatabase’ , @backupType='F', @backupLocation='D:\Backup\'"

this is my batch file query for backup database. but when i run this its giving the following error:

'EXEC sp_BackupDatabases @databaseName=’myDatabase’ , @backupType='F', @backupLocation='D:\Backup\'': Unexpected argument.

Was it helpful?

Solution

The issue is with how you are using the sqlcmd utility.

When specifying an inline query, it should be preceded with the -q or -Q parameter. The former instructs the utility to just execute the query (and stay in the sqlcmd shell), while the latter additionally causes the utility to exit after the execution, which is probably what you need here.

So, to fix the issue, modify your command line as highlighted below:

sqlcmd -S servername\sqldeveloper -E -Q "EXEC sp_BackupDatabases …"

There's also another potential issue, unless it is just a typo made while adding the command to the question. It is about the "curly" quotation marks around myDatabase: they probably need to be replaced with straight ones (’myDatabase’ -> 'myDatabase'), or the name will likely not be recognised.

You can run sqlcmd -? at the command prompt to familiarise yourself with (or remind yourself about) how to use the various sqlcmd options properly. You can also read about the utility at MSDN, e.g. here.

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