Unanswered: Restoring Database using SQL-DMO gives me an error on another DB Server
Hi I am trying to restore a database using SQL-DMO. Restoring works on my development computer, but it does not work on my colleague's development computer. Although there are no users using the database in question, I get the following error message while attempting to restore the backup file:
Exclusive access could not be obtained. Database is in use.
Do I have to do anything in particular? Here is my snippet of code (VB.net). Thanks.
Dim my_srv As SQLDMO._SQLServer = New SQLDMO.SQLServerClass
my_srv.Connect(my_config.get_ServerName(), my_config.get_DBUserID(), my_config.get_Password)
'COPY FILE TO SPECIFIC DIRECTORY ON SERVER
Dim my_file As File
my_file.Copy(Me.txtFilePath.Text, "\\" + my_config.get_ServerName + my_config.get_backupfolder_string + "tempcas.bak")
I'm connecting to a database named CAS. Anyway the database name would vary on what I have set in an xml file. As you can see from my code, I am getting the database name from a class.
I've found that it is because my query analyser is open and pointed to CAS, this causes a process to be created. I can see this process with a status RUNNABLE, dbName CAS and program name SQL Query Analyser when I run sp_who2. When I change query analyzer to point to another database, this process will disappear and I would be able to restore my CAS database.
Is this what you were trying to tell me? Thanks for your replies.
I am now concerned about what would happen if there are multiple users using the application.