BackUp e Restore con MSDE
Vi illustro di seguito un esempio di codice per poter effettuare il Backup ed il successivo Restore di un Database MSDE....
Imports System.Data.SqlClient
Dim SqlConn As New SqlConnection()
Dim SqlCmd As New SqlCommand()
SqlConn.ConnectionString="Data Source=(local);Initial Catalog=master;Integrated Secutity=SSPI"
SqlConn.Open()
Rem -----Backup
SqlCmd.Connection=SqlConn
SqlCmd.CommandType=CommandType.Text
SqlCmd.CommandText="BACKUP DATABASE [nomedb] TO DISK = N'D:\nomedb.bak' WITH INIT,NAME = N'nomedb Backup'"
Try
SqlCmd.ExecuteNonQuery()
Catch
Msgbox(err.description)
ENd Try
SqlCmd.Dispose()
Rem -----restore
SqlCmd.Connection=SqlConn
SqlCmd.CommandType=CommandType.Text
SqlCmd.CommandText = "RESTORE DATABASE [nomedb] FROM DISK = N'D:\nomedb.bak' WITH FILE =1,RECOVERY,MOVE N'nomedb TO N'C:\Programmi\Microsoft Sql Server\MSSQL\data\nomedb.mdf', MOVE N'nomedb_log' TO N'C:\Programmi\Microsoft Sql Server\MSSQL\data\nomedb_log.ldf'"
Try
SqlCmd.ExecuteNonQuery()
Catch
Msgbox(err.description)
ENd Try
SqlCmd.Dispose()
SqlConn.Dispose()
SqlConn.Close()
martedì, 04 apr 2006 Ore. 10.54