Apr 23, 2009 at 3:22 PM
Edited Apr 23, 2009 at 3:27 PM
When I try to restore my database from a shapshot with the following statement (the restore is executed in the TestSuiteTeardown):
<SqlCommand connectionRef="master" returnsValue="false">
RESTORE DATABASE MyDatabase FROM DATABASE_SNAPSHOT = 'MyDatabase_SSISUnit'
I get the following message:
Error occurred: RESTORE DATABASE is terminating abnormally.
Database state cannot be changed while other users are using the database 'MyDatabase'
This is just a "regular" error message that is generated by SQL Server. The message itself is clear: there are still connections to MyDatabase which prevents the restore from taking place. This implies that ssisUnit still has a connection to the database.
I have set up two connections:
<Connection name="MyDatabase" connection="Data Source=(local)\SQL2005;Initial Catalog=MyDatabase;Provider=SQLNCLI.1;Integrated Security=SSPI;" connectionType="ConnectionString"/>
<Connection name="master" connection="Data Source=(local)\SQL2005;Initial Catalog=master;Provider=SQLNCLI.1;Integrated Security=SSPI;" connectionType="ConnectionString"/>
The restore command is executed with the master connection. But appearently ssisUnit still maintains a connection to MyDatabase. I have read that others also use the snapshot technique to reset their database back to the original state. Is there a way to prevent
this error from occuring?