Detach mdf file on form closing
Hi, Using Visual Studio (2008) in Vb net along with SQLExpress (2008) in Windows Forms, how to detach the database every time I close the Appby programmation. Can it be done on form closing, if so please show us. Thank in advance
Hirendra SisodiyaPosted May 2, 2011, 5:03 AM
write code on form closing event
Dim conn As new SqlClient.SqlConnectionDim cmd As New SqlClient.SqlCommand()
Dim ConnectionString As String = "Data Source=" & SERVER NAME & ";Initial Catalog=master;Integrated Security=True"conn = conn.ConnectionString = ConnectionString
conn.Open()
Dim sqlDetech As String = "sp_detach_db '" & database name & "', 'true'"cmd.CommandText = sqlDetech
cmd.Connection = conn
cmd.ExecuteNonQuery()
please mark as answer if it helps