Computing.Net > Forums > Disk Operating System > database restore from CLI

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

database restore from CLI

Reply to Message Icon

Name: trusp
Date: January 27, 2009 at 01:44:35 Pacific
OS: DOS
CPU/Ram: Intel DUO
Product: Ms / Ms/e6550
Subcategory: General
Comment:

Hi
This is the batch script i am using for database backup & Restore.

set UN=%1
set PWD=%2
set SER=%3
set DB=%4
sqlcmd -U %UN% -P %PWD% -S %SER% -Q "EXEC sp_dboption '%DB%','dbo use only','TRUE'"
sqlcmd -U %UN% -P %PWD% -S %SER% -Q "RESTORE DATABASE %DB% FROM DISK='%DB%.bak'"

Here I need to make the database to be "dbo use only" from the CLI
So before restoring I need to execute the following command
EXEC sp_dboption '%DB-NAME%','dbo use only','TRUE'

But here the issue is:
If database already exists this line not makes any error.
Else if database was been dropped. Then it produces the following error:

Msg 15010, Level 16, State 1, Server MT-SERVER123, Procedure sp_dboption, Line 64
The database 'testDatabase' does not exist. Use sp_helpdb to show available databases.
Available databases:
--------
.....

So here I need to check whether a database exist and need to run the command:
EXEC sp_dboption '%DB-NAME%','dbo use only','TRUE'

Is there any way to check whether the database exists and then execute the above command.

Please help me out in this issue asap
Thanks in Advance

Trusp



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: January 27, 2009 at 03:20:00 Pacific
Reply:

See your post in the Programming Forum; by the way this is not a DOS question but a NT batch issue.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: database restore from CLI

Restore a msbackup from DOS ver. 6.0 www.computing.net/answers/dos/restore-a-msbackup-from-dos-ver-60/10.html

restore file from dos 6.1 update www.computing.net/answers/dos/restore-file-from-dos-61-update/4077.html

restore on Compaq Presario www.computing.net/answers/dos/restore-on-compaq-presario/10665.html