Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restore Database Using .Net Program 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
0
36
US
I'm trying to restore a DB using a stored procedure called from a .Net program and would like a little help.
Code:
-- Error checking removed
ALTER DATABASE Cemetery1 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
RESTORE DATABASE Cemetery1 FROM DISK = @RestoreFileName
ALTER DATABASE Cemetery1 SET MULTI_USER;
I get an error saying it cannot do this because it is use by this session. I understand that because I accessed the stored proc that is in the DB I am trying to restore. It also says I should use the master DB for this. Does that mean I have to set up a user and the stored procedure in the master DB? Then open the master DB from the .Net program and run the master DB proc. I'm a little worried about what permissions I would have to give this user in the master DB. Any guidance on how to accomplish this would be appreciated.


Auguy
Sylvania/Toledo Ohio
 
In order for a user to restore a database, there are certain server level permissions required. Assuming your user already has those permissions, then they will already be allowed to connect to master to perform certain operations (like restoring a database).

Basically, what I'm saying is that you don't need to do anything special to give the user permissions to the master database. Simply connect to that database and do the restore.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks George, I'm also looking into SqlCmd utility.

Auguy
Sylvania/Toledo Ohio
 
I'm assuming I have to put the stored proc into the master database. Doses that sound right?

Auguy
Sylvania/Toledo Ohio
 
yes

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks again George, great answers as always!

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top