Restore SQL Database from C#.NET Code Problem

J

Joe Cool

I am working on an application that uses a Microsoft SQL database. I
want to implement a Restore database from backup function. While
running it has two connections to the server, one to the master
database and one to the applicaiton's database.

When the user kicks of the restore, it closes the current connection
to the application database. Then it loops through all entries from an
sp_who query where the dbname matches the applicaiton database and
kills them, making sure it kills my spid last. I then run the RESTORE
transact-sql command using the connection to the master database.

After a few seconds, it throws an exception with the message:

Exclusive access could not be obtained because the database is in use.
RESTORE DATABASE is terminating abnormally.

I thought I doing everything I could to make sure there were no active
connections.

Any help would be appreciated.
 
S

Sangram

Ensure that the database you are trying to restore is not used by SQL Server neither any running application or process.

If so is the case, close the application and run the restore command again.



Joe Cool wrote:

Restore SQL Database from C#.NET Code Problem
15-Aug-09

I am working on an application that uses a Microsoft SQL database.
want to implement a Restore database from backup function. Whil
running it has two connections to the server, one to the maste
database and one to the applicaiton's database

When the user kicks of the restore, it closes the current connectio
to the application database. Then it loops through all entries from a
sp_who query where the dbname matches the applicaiton database an
kills them, making sure it kills my spid last. I then run the RESTOR
transact-sql command using the connection to the master database

After a few seconds, it throws an exception with the message

Exclusive access could not be obtained because the database is in use
RESTORE DATABASE is terminating abnormally

I thought I doing everything I could to make sure there were no activ
connections

Any help would be appreciated.

Previous Posts In This Thread:

Restore SQL Database from C#.NET Code Problem
I am working on an application that uses a Microsoft SQL database.
want to implement a Restore database from backup function. Whil
running it has two connections to the server, one to the maste
database and one to the applicaiton's database

When the user kicks of the restore, it closes the current connectio
to the application database. Then it loops through all entries from a
sp_who query where the dbname matches the applicaiton database an
kills them, making sure it kills my spid last. I then run the RESTOR
transact-sql command using the connection to the master database

After a few seconds, it throws an exception with the message

Exclusive access could not be obtained because the database is in use
RESTORE DATABASE is terminating abnormally

I thought I doing everything I could to make sure there were no activ
connections

Any help would be appreciated.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Featured Product / Service Review: TekPub
http://www.eggheadcafe.com/tutorial...2e-39384482c80e/featured-product--servic.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top