Click here to Skip to main content
16,004,833 members
Home / Discussions / Database
   

Database

 
GeneralMultiple Queries in ADO Pin
brdavid7-Jul-04 14:39
brdavid7-Jul-04 14:39 
GeneralRe: Multiple Queries in ADO Pin
Michael Potter8-Jul-04 3:29
Michael Potter8-Jul-04 3:29 
GeneralRe: Multiple Queries in ADO Pin
brdavid8-Jul-04 4:26
brdavid8-Jul-04 4:26 
GeneralRe: Multiple Queries in ADO Pin
Michael Potter8-Jul-04 5:01
Michael Potter8-Jul-04 5:01 
Generalcan't detach database Pin
dmbf1b57-Jul-04 10:38
dmbf1b57-Jul-04 10:38 
GeneralRe: can't detach database Pin
Mike Dimmick7-Jul-04 11:31
Mike Dimmick7-Jul-04 11:31 
GeneralRe: can't detach database Pin
Grimolfr7-Jul-04 13:52
Grimolfr7-Jul-04 13:52 
GeneralStill doesn't work - more info Pin
dmbf1b57-Jul-04 16:49
dmbf1b57-Jul-04 16:49 
Hi,

Thanks for the good ideas above. I tried them and still have the same problem. I created a simple windows form project that reproduces the problem using the Northwind database, and narrows it down to the SqlConnection object. I have a single form with a single button. When the form loads, it creates a connection, opens it, changes the database to master, closes the connection, and disposes the connection object. When the button is clicked, it attempts to detach the database. That raises the error, "Cannot detach the database 'Northwind' because it is currently in use."

I can't figure out what is wrong with this simple code! Any ideas?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'select a single value from a table in the database

Dim mConn As New SqlClient.SqlConnection("data source=(local);initial catalog=Northwind;integrated security=SSPI")

mConn.Open()
mConn.ChangeDatabase("master")
mConn.Close()
mConn.Dispose()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'detach the database

Dim mConn As New SqlClient.SqlConnection("data source=(local);initial catalog=master;integrated security=SSPI")
Dim sSQL = "sp_detach_db 'Northwind'"
Dim Command As New SqlClient.SqlCommand(sSQL, mConn)

Command.Connection.Open()
Try
Command.ExecuteNonQuery()
Catch ex As Exception
Debug.WriteLine(ex.Message)
MsgBox(ex.Message)

Finally
mConn.ChangeDatabase("master")
Command.Connection.Close()
mConn.Dispose()
Command.Dispose()
End Try

End Sub

GeneralRe: Still doesn't work - more info Pin
Grimolfr8-Jul-04 5:28
Grimolfr8-Jul-04 5:28 
GeneralRe: Still doesn't work - more info Pin
dmbf1b58-Jul-04 9:19
dmbf1b58-Jul-04 9:19 
GeneraltSQL: Share -> Database Table (DTS?) Pin
partt7-Jul-04 5:19
partt7-Jul-04 5:19 
GeneralFinding the primary key Pin
Colin Angus Mackay7-Jul-04 4:45
Colin Angus Mackay7-Jul-04 4:45 
GeneralRe: Finding the primary key Pin
Mike Dimmick7-Jul-04 5:17
Mike Dimmick7-Jul-04 5:17 
GeneralRe: Finding the primary key Pin
Colin Angus Mackay7-Jul-04 5:28
Colin Angus Mackay7-Jul-04 5:28 
GeneralRe: Finding the primary key Pin
Grimolfr7-Jul-04 5:46
Grimolfr7-Jul-04 5:46 
GeneralRe: Finding the primary key Pin
Colin Angus Mackay7-Jul-04 6:01
Colin Angus Mackay7-Jul-04 6:01 
GeneralRe: Finding the primary key Pin
Grimolfr7-Jul-04 6:15
Grimolfr7-Jul-04 6:15 
GeneralCannot call Oracle stored procedure from C++ Pin
pankajdaga6-Jul-04 9:35
pankajdaga6-Jul-04 9:35 
GeneralRe: Cannot call Oracle stored procedure from C++ Pin
Chris Meech7-Jul-04 3:04
Chris Meech7-Jul-04 3:04 
GeneralADO.NET - BindingContext and Disappearing Rows Pin
mikasa6-Jul-04 8:54
mikasa6-Jul-04 8:54 
GeneralArabic to English Conversion Pin
Anonymous6-Jul-04 7:13
Anonymous6-Jul-04 7:13 
Generaloverwite/add between two databases help Pin
Anonymous6-Jul-04 3:51
Anonymous6-Jul-04 3:51 
Questioncan anyone optimize this query Pin
xcavin6-Jul-04 3:15
xcavin6-Jul-04 3:15 
AnswerRe: can anyone optimize this query Pin
RichardGrimmer6-Jul-04 4:12
RichardGrimmer6-Jul-04 4:12 
AnswerRe: can anyone optimize this query Pin
Michael Potter6-Jul-04 7:28
Michael Potter6-Jul-04 7:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.