Hi Bill,
Thanks for your reply! I tried to shut down the sql server, then start
the sql
server again. Unfortunately, it did not work. The following is the
code:
//create an instance of a server class
SQLDMO.SQLServer srv = new SQLDMO.SQLServer();
//connect to the server
srv.Connect("local)\\NetSDK", "sa", "abc");
try
{
srv.Shutdown(5000); // stop db server, wait for 2 seconds
}
catch (Exception e)
{
; // do nothing
}
Thread.Sleep(10000); // sleep 10 seconds
// restart server
srv.Start(true, "(local)\\NetSDK", "sa", "abc");
//create a restore class instance
SQLDMO.Restore restore = new SQLDMO.Restore();
restore.Action = 0; // full db restore
//set the database to the chosen database
restore.Database = "mydbfile";
restore.Files = Path.GetFullPath(@"..\..\backup\DBLPS.bak");
SqlConnection conn = new SqlConnection("server=(local)\\NetSDK;
uid=sa; password=abc; pooling=false");
// Restore the database
restore.ReplaceDatabase = true;
restore.SQLRestore(srv);
An exception is thrown at srv.Start with message:
"An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in myapp.exe
Additional information: [SQL-DMO]This server object is already
connected."
I'd like to know what your approach is to use SQL DMO to stop and
restart the SQL server?
Thanks a lot!
Mandy
William \(Bill\) Vaughn said:
I talk about this in my ADO workshop. One approach (that seems to work)
is
to use SQL
DMO to stop the server and restart in single-user mode. The problem with
the
pools is that they don't close the connections for 4-8 minutes (or so)
after
disconnect unless the application is ended. DMO forces the server to
disconnect and close. After that you can execute the restore from SQL
DMO.
My next workshop is in Chicago in mid October--if there are still seats
left.
--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
Mandy said:
Hello,
To resotre MSDE database, the connection pool must be disabled. I set
pooling=false in the connection string, i.e.,
SqlConnection conn = new SqlConnection("server=(local)\\NetSDK;
database=mydb; uid=sa; password=abc; pooling=false;");
It seems that the connection pool was not disabled. Here are the error
messages I got:
[Microsoft][ODBC SQL Server Driver][SQL Server]Exclusive access could
not be obtained because the database is in use.
[Microsoft][ODBC SQL Server Driver][SQL Server]RESTORE DATABASE is
terminating abnormally.
Any ideas? Are there any other ways to disable the connection pool?
Any help would be appreciated!
Mandy