Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
TimKellSSi
Starting Member
4 Posts |
Posted - 2008-03-17 : 14:06:34
|
I am trying to backup the sql database files from a local computer to a server location through vb.net 2005. Is there a simple way to do this? Every time I try to detach the database, I cannot because the database is in use. Is there something I am missing with this?Thanks |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-03-17 : 23:51:27
|
Why don't do db backup? It's online operation. |
 |
|
TimKellSSi
Starting Member
4 Posts |
Posted - 2008-03-20 : 09:27:29
|
I'm able to create a backup file using the following codeDim a As SQLDMO.BackupDim svr As SQLDMO._SQLServerTrya = New SQLDMO.BackupClass()svr = New SQLDMO.SQLServerClass()svr.LoginSecure = Falsesvr.Connect(ServerName, ADMIN_UID, ADMIN_PWD)a.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Databasea.Database = dbNamea.Files = path & BACKUP_FILEa.BackupSetName = dbNamea.BackupSetDescription = "Database backup"a.Initialize = Truea.SQLBackup(svr)svr.DisConnect()svr = NothingCatch ex As Exception MessageBox.Show(ex.ToString)End TryThe above code runs with no problem and creates the backup file. However, when I try to run the restore code:Dim restore As SQLDMO.RestoreDim svr As SQLDMO._SQLServerTryrestore = New SQLDMO.RestoreClass()svr = New SQLDMO.SQLServerClass()svr.LoginSecure = Falsesvr.Connect(ServerName, ADMIN_UID, ADMIN_PWD)restore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Databaserestore.Database = dbNamerestore.Files = path & BACKUP_FILErestore.BackupSetName = dbNamerestore.FileNumber = 1restore.SQLRestore(svr)svr.DisConnect()svr = NothingCatch ex As Exception MessageBox.Show(ex.ToString)End TryI get an error stating that the BackupSetName is not supported by the Restore object.What am I missing with this? |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
TimKellSSi
Starting Member
4 Posts |
Posted - 2008-03-20 : 11:08:50
|
Thanks for the input so far. In the example you've shown, there is a line: sqlserver.Connect("192.168.19.25","sa","sa"). What is this IP address? Is it the local computer when SQL Server is, or is it the server where the backup is? I've tried using the local server by name and here is the error I get:System.Runtime.InteropServices.COMException (0x80045068): [SQL-DMO]BackupSetName property is not supported by the Restore object. at SQLDMO.RestoreClass.set_BackupSetName(String pRetVal) at Main.Restore(String dbName, String path) in C:\dev\VB2005.NET\Solution\Project\Main.vb:line 255When I use the IP address listed above, I just time out.Thanks |
 |
|
TimKellSSi
Starting Member
4 Posts |
Posted - 2008-03-20 : 11:37:47
|
I would like to those that helped me with this problem.I simply commented out the following line:restore.BackupSetName = dbNameand the restore worked fine. |
 |
|
|
|
|
|
|