I can run this command in SqlManager to detach the db
ALTER DATABASE mydb SET OFFLINE WITH ROLLBACK IMMEDIATE
GO
dbo.sp_detach_db @dbname = N'mydb',@keepfulltextindexfile = N'false'
When I use the same connection running the same commadn via ado.net fails with error:
The database 'mydb' can not be opened because it is offline
(Error is translated from german.)
The Ado.Net code is
SqlCommand cmdOffline = new SqlCommand(@"ALTER DATABASE mydb SET OFFLINE WITH ROLLBACK IMMEDIATE");
cmdOffline.Connection = prepareMasterDBConnection;
cmdOffline.ExecuteNonQuery();
SqlCommand cmdDetach = new SqlCommand(@"dbo.sp_detach_db @dbname = N'mydb',@keepfulltextindexfile = N'false'");
cmdDetach.Connection = prepareMasterDBConnection;
cmdDetach.ExecuteNonQuery();
The connection is set to master - DB and open. The first commadn exceutes sucessfully.
What is the difference here when calling the code from ado and from sql-manager?