Reputation: 683
I just spent a long time trying to figure this one out, so Id thought Id post my solution.
QUESTION: "I am about to restore a given database in C# using SMO, and would like to check to see if I have access to the db before I restore. How do I do that?"
Upvotes: 2
Views: 79
Reputation: 683
ANSWER:
Use the following code to see if a given database is in use:
Server srv = new Server();
if (srv.GetActiveDBConnectionCount(dbName) > 0)
{
MessageBox.Show("Database '" + dbName + "' is currently in use");
}
Upvotes: 1