Sunday, February 12, 2012

backing up using sql-dmo

Hi,
I am trying to backkup my app's database using SQL - DMO in vb.net. Here is my code, the code complains about the backupdevice not present. I just want to back the db to my D drive with name as myBackup.bak, so the full path will be D:\myBackup.bak.
Public WithEvents dmoBackup As New SQLDMO.Backup
Dim svr As New SQLDMO.SQLServer
svr.LoginTimeout = 30
svr.Connect("(local)\MyInstanceName", "MyUser", "MyPassword")
dmoBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
dmoBackup.Database = "MyDatabase"
dmoBackup.Files = "D:\myBackup.bak"
dmoBackup.Devices = dmoBackup.Files
dmoBackup.SQLBackup(svr)
The code is able to create server object fine, but crashes at the last line. This is the entire code I have, I haven't created any backup device, what should I do to make this work.
Please note that my backup restore using the same database and user etc in T-SQL works fine. I just need DMO to show progress bar to the user while backing up the db.
Thanks
dev
hi dev,
"dev_kh" <devkh@.discussions.microsoft.com> ha scritto nel messaggio
news:F5DFA76A-9458-4E45-A772-9CA53D481D7A@.microsoft.com...
> Hi,
>...
> Public WithEvents dmoBackup As New SQLDMO.Backup
> Dim svr As New SQLDMO.SQLServer
> svr.LoginTimeout = 30
> svr.Connect("(local)\MyInstanceName", "MyUser", "MyPassword")
> dmoBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
> dmoBackup.Database = "MyDatabase"
> dmoBackup.Files = "D:\myBackup.bak"
remove this line
> dmoBackup.Devices = dmoBackup.Files <--

> dmoBackup.SQLBackup(svr)
>
and it shoul'd be fine...
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.8.0 - DbaMgr ver 0.54.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||Thanks Andrea. This works but there is a problem. Here me out:
1> If I pass the path as "D:\myBackup.bak" then it backsup fine.
2> If I pass the path as "D:\OnWord\myBackup.bak" then it backsup fine.
3> But if I pass the path as "D:\Two Words\myBackup.bak" then it complains saying "cannot open backup device..".
So basically if any directory in the path as space in between chars, then the backup fails.. Is this a know issue. How do I resolve it. In actual terms, my path is something like:
"C:\Program Files\..."
Please help.
dev
"Andrea Montanari" wrote:

> hi dev,
> "dev_kh" <devkh@.discussions.microsoft.com> ha scritto nel messaggio
> news:F5DFA76A-9458-4E45-A772-9CA53D481D7A@.microsoft.com...
> remove this line
>
> and it shoul'd be fine...
> --
> Andrea Montanari (Microsoft MVP - SQL Server)
> http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
> DbaMgr2k ver 0.8.0 - DbaMgr ver 0.54.0
> (my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
> interface)
> -- remove DMO to reply
>
|||hi dev,
"dev_kh" <devkh@.discussions.microsoft.com> ha scritto nel messaggio
news:D4641BED-0740-480C-8294-C16B88A5FF09@.microsoft.com...
> Thanks Andrea. This works but there is a problem. Here me out:
> 1> If I pass the path as "D:\myBackup.bak" then it backsup fine.
> 2> If I pass the path as "D:\OnWord\myBackup.bak" then it backsup fine.
> 3> But if I pass the path as "D:\Two Words\myBackup.bak" then it complains
saying "cannot open backup device..".
> So basically if any directory in the path as space in between chars, then
the backup fails.. Is this a know issue. How do I resolve it. In actual
terms, my path is something like:
enclose it in square brackets like .Files = "[D:\Two Words\my Backup.bak]"
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.8.0 - DbaMgr ver 0.54.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply

No comments:

Post a Comment