473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Backing up with SQL MO

Hi,

I'm trying to programmatically backup a database (SQL 2005). I get a
"Device not found" error when I specify a full user given path in the
backup, but when I just specify a filename it works, putting the backup into
the SQL folder: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup.
What I want to do is have the backup written to the local user data folder.
My code looks like this (VB.NET):
theServer = New Server(m_Source.Server)

m_Backup = New Backup

m_Backup.Action = BackupActionType.Database
m_Backup.BackupSetDescription = "Backup of zzz"
m_Backup.BackupSetName = "zzz Backup"
m_Backup.Database = m_Source.Catalog

tempPath = Application.LocalUserAppDataPath + "\backup_zzz.bat"

theDeviceItem = New BackupDeviceItem(tempPath, DeviceType.File)

m_Backup.Devices.Add(theDeviceItem)
m_Backup.Checksum = True
m_Backup.ContinueAfterError = True
m_Backup.Incremental = False
m_Backup.ExpirationDate = New Date(2006, 10, 5)
m_Backup.LogTruncation = BackupTruncateLogType.Truncate
m_Backup.MediaDescription = "file backup"
m_Backup.Initialize = True
m_Backup.PercentCompleteNotification = 10
m_Backup.Restart = True
m_Backup.RetainDays = 5
m_Backup.SqlBackup(theServer)
Any thoughts?
Thanks
Robin
Oct 21 '06 #1
9 3315
Let's clarify this a bit. Is this code being run on, say, WORKSTATIONA and
the SQL Server is on SERVERB? If so, the way to write the backup to
WORKSTATIONA is:

1) Have SQL Server on SERVERB running under a domain account.
2) Have a share on WORKSTATIONA
3) Grant read/write privileges to the share for the account in #1 above.
4) Specify the full UNC name to the backup file on WORKSTATIONA when you
give it the path: \\WORKSTATIONA\MyShare\MyFile.bak

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
"Robinson" <bb*@bbb.comwrote in message
news:mO******************************@giganews.com ...
Hi,

I'm trying to programmatically backup a database (SQL 2005). I get a
"Device not found" error when I specify a full user given path in the
backup, but when I just specify a filename it works, putting the backup into
the SQL folder: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup.
What I want to do is have the backup written to the local user data folder.
My code looks like this (VB.NET):
theServer = New Server(m_Source.Server)

m_Backup = New Backup

m_Backup.Action = BackupActionType.Database
m_Backup.BackupSetDescription = "Backup of zzz"
m_Backup.BackupSetName = "zzz Backup"
m_Backup.Database = m_Source.Catalog

tempPath = Application.LocalUserAppDataPath + "\backup_zzz.bat"

theDeviceItem = New BackupDeviceItem(tempPath, DeviceType.File)

m_Backup.Devices.Add(theDeviceItem)
m_Backup.Checksum = True
m_Backup.ContinueAfterError = True
m_Backup.Incremental = False
m_Backup.ExpirationDate = New Date(2006, 10, 5)
m_Backup.LogTruncation = BackupTruncateLogType.Truncate
m_Backup.MediaDescription = "file backup"
m_Backup.Initialize = True
m_Backup.PercentCompleteNotification = 10
m_Backup.Restart = True
m_Backup.RetainDays = 5
m_Backup.SqlBackup(theServer)
Any thoughts?
Thanks
Robin
Oct 21 '06 #2

"Tom Moreau" <to*@dont.spam.me.cips.cawrote in message
news:uh**************@TK2MSFTNGP05.phx.gbl...
Let's clarify this a bit. Is this code being run on, say, WORKSTATIONA
and
the SQL Server is on SERVERB? If so, the way to write the backup to
WORKSTATIONA is:

1) Have SQL Server on SERVERB running under a domain account.
2) Have a share on WORKSTATIONA
3) Grant read/write privileges to the share for the account in #1
above.
4) Specify the full UNC name to the backup file on WORKSTATIONA when
you
give it the path: \\WORKSTATIONA\MyShare\MyFile.bak

Hi, sorry I should have put it into context. This is on a single developer
machine at present. It seems SQLMO backup only wants to write to the
default backup location and only allows me to specify a filename, not a full
file path. So I'm using the Server.Settings object to find that default
location and then move it across to some user defined location. I was
rather hoping to avoid the move and just write it out there in the first
instance.
Oct 21 '06 #3
Check out page 7 of this:

http://download.microsoft.com/docume...hol/HOL068.pdf

It's bare metal but it works. Try cloning from it as a starting point.

HTH

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
"Robinson" <bb*@bbb.comwrote in message
news:qa******************************@giganews.com ...

"Tom Moreau" <to*@dont.spam.me.cips.cawrote in message
news:uh**************@TK2MSFTNGP05.phx.gbl...
Let's clarify this a bit. Is this code being run on, say, WORKSTATIONA
and
the SQL Server is on SERVERB? If so, the way to write the backup to
WORKSTATIONA is:

1) Have SQL Server on SERVERB running under a domain account.
2) Have a share on WORKSTATIONA
3) Grant read/write privileges to the share for the account in #1
above.
4) Specify the full UNC name to the backup file on WORKSTATIONA when
you
give it the path: \\WORKSTATIONA\MyShare\MyFile.bak

Hi, sorry I should have put it into context. This is on a single developer
machine at present. It seems SQLMO backup only wants to write to the
default backup location and only allows me to specify a filename, not a full
file path. So I'm using the Server.Settings object to find that default
location and then move it across to some user defined location. I was
rather hoping to avoid the move and just write it out there in the first
instance.
Oct 21 '06 #4

"Tom Moreau" <to*@dont.spam.me.cips.cawrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
Check out page 7 of this:

http://download.microsoft.com/docume...hol/HOL068.pdf

It's bare metal but it works. Try cloning from it as a starting point.

HTH

--
Tom
Thanks for that, but it's not much more use than the existing documentation
on MSDN to be honest. :/
Oct 21 '06 #5
So changing the file and path in the example code didn't work? What error
did it give you?

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
"Robinson" <bb*@bbb.comwrote in message
news:F6********************@giganews.com...

"Tom Moreau" <to*@dont.spam.me.cips.cawrote in message
news:eO**************@TK2MSFTNGP04.phx.gbl...
Check out page 7 of this:

http://download.microsoft.com/docume...hol/HOL068.pdf

It's bare metal but it works. Try cloning from it as a starting point.

HTH

--
Tom
Thanks for that, but it's not much more use than the existing documentation
on MSDN to be honest. :/
Oct 21 '06 #6

"Tom Moreau" <to*@dont.spam.me.cips.cawrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
So changing the file and path in the example code didn't work? What error
did it give you?

--
Tom
Hi Tom,

It must be some kind of permissions error, even though I'm a local
administrator (this is a stand-alone developer machine in any case), because
I'm getting the same error in SQL Management Studio when I try to perform a
backup (and SMS uses SQL-MO anyway), unless the directory I specify for the
location of the backup media is the MSSQL backup directory in Program Files.
The error information from management studio looks like this (pasted dialog
text below). Now the strange thing is, I'm getting an error "not found",
but I know it's there because I selected it from the folder browser dialog
Management Studio presented to me. I've tried various other locations too,
with no joy.

Robin



TITLE: Microsoft SQL Server Management Studio Express
------------------------------

Backup failed for Server 'ROBS\SQLEXPRESS'.
(Microsoft.SqlServer.Express.Smo)

For help, click:
http://go.microsoft.com/fwlink?ProdN...r&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

System.Data.SqlClient.SqlError: Cannot open backup device 'd:\robs.bak'.
Operating system error 5(error not found). (Microsoft.SqlServer.Express.Smo)

For help, click:
http://go.microsoft.com/fwlink?ProdN...0&LinkId=20476

------------------------------
BUTTONS:

OK
------------------------------

Oct 22 '06 #7
Under what account is SQL Server running? Have you tried creating a domain
account and running SQL under that - after granting read/write permissions
on drive D:?

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
"Robinson" <bb*@bbb.comwrote in message
news:5v******************************@giganews.com ...

"Tom Moreau" <to*@dont.spam.me.cips.cawrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
So changing the file and path in the example code didn't work? What error
did it give you?

--
Tom
Hi Tom,

It must be some kind of permissions error, even though I'm a local
administrator (this is a stand-alone developer machine in any case), because
I'm getting the same error in SQL Management Studio when I try to perform a
backup (and SMS uses SQL-MO anyway), unless the directory I specify for the
location of the backup media is the MSSQL backup directory in Program Files.
The error information from management studio looks like this (pasted dialog
text below). Now the strange thing is, I'm getting an error "not found",
but I know it's there because I selected it from the folder browser dialog
Management Studio presented to me. I've tried various other locations too,
with no joy.

Robin



TITLE: Microsoft SQL Server Management Studio Express
------------------------------

Backup failed for Server 'ROBS\SQLEXPRESS'.
(Microsoft.SqlServer.Express.Smo)

For help, click:
http://go.microsoft.com/fwlink?ProdN...r&LinkId=20476

------------------------------
ADDITIONAL INFORMATION:

System.Data.SqlClient.SqlError: Cannot open backup device 'd:\robs.bak'.
Operating system error 5(error not found). (Microsoft.SqlServer.Express.Smo)

For help, click:
http://go.microsoft.com/fwlink?ProdN...0&LinkId=20476

------------------------------
BUTTONS:

OK
------------------------------

Oct 22 '06 #8

"Tom Moreau" <to*@dont.spam.me.cips.cawrote in message
news:eZ**************@TK2MSFTNGP04.phx.gbl...
Under what account is SQL Server running? Have you tried creating a
domain
account and running SQL under that - after granting read/write
permissions
on drive D:?
Where do I find out which account 2005 is running under?

Anyway, I can't write a backup to C drive either (i.e. to my desktop) - I'm
not on a domain and I am running as administrator on this PC. I've
implemented a Restore database dialog also using SMO, and it let me pick up
backups from anywhere.

Robin
Oct 23 '06 #9
Use SQL Server Configuration Manager. I'd still create a user account on
your PC, grant it read/write privileges to the target folder and re-try.

It doesn't matter that you are an admin. It matters what privileges SQL
has.

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
"Robinson" <bb*@bbb.comwrote in message
news:na********************@giganews.com...

"Tom Moreau" <to*@dont.spam.me.cips.cawrote in message
news:eZ**************@TK2MSFTNGP04.phx.gbl...
Under what account is SQL Server running? Have you tried creating a
domain
account and running SQL under that - after granting read/write
permissions
on drive D:?
Where do I find out which account 2005 is running under?

Anyway, I can't write a backup to C drive either (i.e. to my desktop) - I'm
not on a domain and I am running as administrator on this PC. I've
implemented a Restore database dialog also using SMO, and it let me pick up
backups from anywhere.

Robin
Oct 23 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mark | last post by:
Hi I'm hoping that some could point me in the right direction for "best practice" in: 1) securely backing up a complete sql7 and 2000 server containing many databases. 2) backing up an...
1
by: Hlpl | last post by:
Hi I have a VB.net windows application that uses an MSDE database I need to give the user the option to backup this data (and later restore it). Ideally I want to back the data up to an empty...
9
by: J. Frank Parnell | last post by:
hello, i dont know asp at all, but i have been asked to backup a database that is used on a site which uses .aspx. i dont need to do anything with it, just copy it and send it along to someone...
0
by: Lyle Fairfield | last post by:
I have posted previously a procedure for backing up a remote MS-SQL db as text. This is a revised version in Javascript/JScript. This backups data and procedures as XML. My purpose in creating...
5
by: Stewart Graefner | last post by:
I would like to know if an Access db can be backed up with the push of a command button. I work with extreamly lazy operators who despite crashing their db's still refuse to see the value in...
5
by: rdemyan via AccessMonster.com | last post by:
I have code in my front end that opens a form for backing up the front end. I'll give a brief description of what the form does: 1) When the backup form opens, it closes all open forms except for...
1
by: rob.w | last post by:
I am new to MySQL. I have an application using MySQL running on Windows Server 2000. If I were using Microsoft SQL Server 2000, I would need special software to back up an open SQL Server database....
1
by: Akaketwa | last post by:
Guys may yu assist me am stuck. Am using v8.1 db2 database on Suse Linux running on an IBM pSeries server. I am aware of the backup utility in db2. I would like to back up the my db2 database to a...
5
by: sammentor | last post by:
I don't know how to go about with writing codes of backing up and restoring data. pls help!
9
by: jim | last post by:
I'd like to get some .net sample code that shows me how to make a complete backup of a hard drive (like my C: drive) to another location (say my D: drive) while the C: drive is in use. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.