SSi_Cincinnati
New member
- Joined
- Feb 15, 2010
- Messages
- 4
- Programming Experience
- 3-5
I am trying to restore a backup file (.bak) to my database, but I keep getting the following error:
Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
I'm using VS2008 (Visual Basic) connecting to SQL Express 2008
I can back the db up just fine, but on restore, it throws the error message
Here is the restore code:
Public Function Restore(ByVal dbName As String, ByVal path As String, ByVal uName As String, ByVal uPass As String) As Boolean
Dim copyGood As Boolean = False
Try
Dim myServer As New Server
Dim aServer As Server
Dim bdi As BackupDeviceItem
Dim dOpts As DatabaseOptions
Dim myRestore As New Restore()
Dim currentDB As Database
'aServer = GetServer()
aServer = New Server(getServerNameFromConString())
myServer = GetServer()
'myServer.Databases(dbName).Drop()
currentDB = New Database(myServer, dbName)
dOpts = currentDB.DatabaseOptions()
myRestore.Database = dbName
If Not currentDB Is System.DBNull.Value Then
aServer.KillAllProcesses(dbName)
End If
bdi = New BackupDeviceItem(path & BACKUP_FILE, DeviceType.File)
myRestore.Devices.AddDevice(path & BACKUP_FILE, DeviceType.File)
Dim DataFileLocation As String = "C:\SSi\Data\" & dbName & ".mdf"
Dim LogFileLocation As String = "C:\SSi\Data\" & dbName & "_log.ldf"
myRestore.NoRecovery = False
myRestore.Action = RestoreActionType.Database
myRestore.Devices.Add(bdi)
myRestore.ReplaceDatabase = True
myRestore.Checksum = True
myRestore.ContinueAfterError = True
myRestore.PercentCompleteNotification = 10
AddHandler myRestore.PercentComplete, AddressOf Restore_PercentComplete
AddHandler myRestore.Complete, AddressOf Restore_Complete
writeToErrorLogAndConsole("Restoring: " & dbName, "DATABASE RESTORE")
' Restore the database
myRestore.SqlRestore(myServer)
currentDB = myServer.Databases(dbName)
currentDB.SetOnline()
copyGood = True
Catch ex As Exception
writeToErrorLogAndConsole(ex.ToString, "DATABASE RESTORE")
MessageBox.Show(ex.ToString)
copyGood = False
End Try
Return copyGood
End Function
I'm not too familiar with the backup/restore functionality, so any help will be appreciated.
Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
I'm using VS2008 (Visual Basic) connecting to SQL Express 2008
I can back the db up just fine, but on restore, it throws the error message
Here is the restore code:
Public Function Restore(ByVal dbName As String, ByVal path As String, ByVal uName As String, ByVal uPass As String) As Boolean
Dim copyGood As Boolean = False
Try
Dim myServer As New Server
Dim aServer As Server
Dim bdi As BackupDeviceItem
Dim dOpts As DatabaseOptions
Dim myRestore As New Restore()
Dim currentDB As Database
'aServer = GetServer()
aServer = New Server(getServerNameFromConString())
myServer = GetServer()
'myServer.Databases(dbName).Drop()
currentDB = New Database(myServer, dbName)
dOpts = currentDB.DatabaseOptions()
myRestore.Database = dbName
If Not currentDB Is System.DBNull.Value Then
aServer.KillAllProcesses(dbName)
End If
bdi = New BackupDeviceItem(path & BACKUP_FILE, DeviceType.File)
myRestore.Devices.AddDevice(path & BACKUP_FILE, DeviceType.File)
Dim DataFileLocation As String = "C:\SSi\Data\" & dbName & ".mdf"
Dim LogFileLocation As String = "C:\SSi\Data\" & dbName & "_log.ldf"
myRestore.NoRecovery = False
myRestore.Action = RestoreActionType.Database
myRestore.Devices.Add(bdi)
myRestore.ReplaceDatabase = True
myRestore.Checksum = True
myRestore.ContinueAfterError = True
myRestore.PercentCompleteNotification = 10
AddHandler myRestore.PercentComplete, AddressOf Restore_PercentComplete
AddHandler myRestore.Complete, AddressOf Restore_Complete
writeToErrorLogAndConsole("Restoring: " & dbName, "DATABASE RESTORE")
' Restore the database
myRestore.SqlRestore(myServer)
currentDB = myServer.Databases(dbName)
currentDB.SetOnline()
copyGood = True
Catch ex As Exception
writeToErrorLogAndConsole(ex.ToString, "DATABASE RESTORE")
MessageBox.Show(ex.ToString)
copyGood = False
End Try
Return copyGood
End Function
I'm not too familiar with the backup/restore functionality, so any help will be appreciated.