Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Restoring SQL DataBase by Code from VB 2010

$
0
0
Hi guys:
Can anyone help please
I am working in VB 2010. My program works wit SQL DataBase "dbCARS" . I Open the conections, make my Queries and Close them and Disposed Inmediately.
From my program I Back-Up the DB and works fine but the Restore Sub Throws this error messege:

"Exclusive access could not be obtained because the database is in use" RESTORE DATABASE is terminating abnormally.
I have no idea what is wrong. I am positive all conections are close.
Private Sub RestoreDB()

Dim con As New SqlConnection("Data_ Source=(local);Initial Catalog=dbCARS;Integrated Security=True")

        Try
            Dim strResSQLsentence As String = "RESTORE DATABASE dbCARS FROM DISK='" & txtDBToRestore.Text & "'"

            con.Open()
            Cmd = New SqlCommand(strResSQLsentence, con)
            Cmd.ExecuteNonQuery()
            MsgBox("DataBase have been restored.")
            con.Close()

        Catch ex As Exception
            MsgBox("Could not be restored.", vbOKOnly)
        Finally
            con.Close()
            con.Dispose()
        End Try

    End Sub



Thanks in advance.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>