QUESTION POSED ON: 07 June 2004
I am trying to perform a RESTORE DATABASE operation, using T-SQL in a
vb.net project on the current SQL database connection. Below are two
code snippets I am working with:
1.
cn.open() 'current connection
Dim comSQL As New SqlClient.SqlCommand
comSQL.Connection = cn
comSQL.CommandText = "RESTORE DATABASE FROM DISK = '' WITH REPLACE, NORECOVERY, PASSWORD = ''"
comSQL.ExecuteNonQuery()
cn.close()
2. Same as above, except I use the SQLDataAdapter, SQLDataReader to
execute the RESTORE clause.
In both cases, the operation fails and the error message 'excusive
access could not be obtained because the database is in use' is generated.
The current database connection is only used as a placeholder for user
databases that are brought into the application for data editing and
reporting, so the current database info is disposable. How can I
perform this restore operation in code?
|