سلام
تمام مشکلات Restore سر این یه خطه کده :
SqlConnection.ClearAllPools()
اینم نمونه کد
Dim strSourcePath As String = Txt_SourcePath.Text + "\myDbBackUp.bak"
Dim strData As String = txt_desPath.Text.Trim + "\myDb_Data.mdf"
Dim strLog As String = txt_desPath.Text.Trim + "\myDb_Data.ldf"
Dim strsql As String = "RESTORE DATABASE TaxiService FROM DISK = '" & strSourcePath & "' " & _
" With Move 'myDbData_Data' TO '" & strData & "', " & _
" Move'myDBData_log' TO '" & strLog & "'"
'Exit Sub
Dim servername As String = "."
Dim db_UserName As String = "sa"
Dim db_Userpass As String = "123456"
Dim StrConn As String = "Server=" & servername & ";Database=Master;User ID=" & db_UserName & " ; Password=" & db_Userpass & ";"
Dim cnn As New SqlConnection(StrConn)
Dim cmdDetach As New SqlCommand("EXEC sp_detach_db 'myDb', 'true'", cnn)
Dim cmdRestore As New SqlCommand(strsql, cnn)
Try
SqlConnection.ClearAllPools()
cnn.Open()
cmdDetach.ExecuteNonQuery()
cmdRestore.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
Finally
If (Not cmdRestore Is Nothing) Then cmdRestore.Dispose()
If (Not cmdDetach Is Nothing) Then cmdDetach.Dispose()
If cnn.State <> ConnectionState.Closed Then cnn.Dispose()
End Try
مشکل من که حل شد امیدوارم مشکل شما هم بااین کد حل بشه .
نیازی هم به dll هایی که دوستان گفتند نداره.
موفق باشید