473,387 Members | 1,798 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,387 software developers and data experts.

SQL DB Backup

OuTCasT
374 256MB
hi all.

I'm trying to back up a database in vs2008 using a stored procedure...

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComAddumpDevice As SqlCommand = New SqlCommand("use master exec sp_addumpdevice 'disk','CompanyBackup','C:\Backup\companyName.bak'", sqlcon)
That creates the dump device for the backup but when i want to back up that database i want to be able to let the user choose the name of the backup

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database ' " & strCompanyName &  " ' to CompanyBackup", sqlcon)
i get the strCompanyName from user input.

it gives me a syntax error

[HTML]An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: Incorrect syntax near 'test'.[/HTML]

but when i do the command without user input

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database test to CompanyBackup", sqlcon)
then it works 100%

Can anyone help
Jul 24 '08 #1
4 1249
MrMancunian
569 Expert 512MB
The difference between the two code parts you posted is the use of quotes (' '). In your first example, working with a variable for the companyname you use quotes.

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database ' " & strCompanyName &  " ' to CompanyBackup", sqlcon)
When you use test as name the query will look like this:

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database ' test ' to CompanyBackup", sqlcon).
When you don't use a variable your code looks like this:

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database test to CompanyBackup", sqlcon)
You see the difference?
Jul 24 '08 #2
OuTCasT
374 256MB
The difference between the two code parts you posted is the use of quotes (' '). In your first example, working with a variable for the companyname you use quotes.

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database ' " & strCompanyName &  " ' to CompanyBackup", sqlcon)
When you use test as name the query will look like this:

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database ' test ' to CompanyBackup", sqlcon).
When you don't use a variable your code looks like this:

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database test to CompanyBackup", sqlcon)
You see the difference?
ya i know

but i cant use a static value because there is going to be different backups to make....

when i insert something from user textbox i use this

Expand|Select|Wrap|Line Numbers
  1. dim sqlcom as sqlcommand = new sqlcommand("insert into Table(employeename,employeesurname)Values('" & txtName.text & "','" & txtSurname.text & "')",sqlcon)
thats what i used to get the inputted values from the textboxes....

why wouldnt it work in the command im doing for the backup
Jul 24 '08 #3
OuTCasT
374 256MB
The difference between the two code parts you posted is the use of quotes (' '). In your first example, working with a variable for the companyname you use quotes.

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database ' " & strCompanyName &  " ' to CompanyBackup", sqlcon)
When you use test as name the query will look like this:

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database ' test ' to CompanyBackup", sqlcon).
When you don't use a variable your code looks like this:

Expand|Select|Wrap|Line Numbers
  1. Dim sqlComBackupDatabase As SqlCommand = New SqlCommand("Backup database test to CompanyBackup", sqlcon)
You see the difference?

ok well i found the problem

Expand|Select|Wrap|Line Numbers
  1. "Backup database " & strCompanyName & " to CompanyBackup"
i jst took out the single quote.....
Jul 24 '08 #4
MrMancunian
569 Expert 512MB
ok well i found the problem

Expand|Select|Wrap|Line Numbers
  1. "Backup database " & strCompanyName & " to CompanyBackup"
i jst took out the single quote.....
That's what I told you in first place <g>
Jul 24 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Andrew E | last post by:
I just took over DBA responsibilities for an Oracle 8i database running on Linux. Although I've been working with relational databases for some time, I'm a bit green on Oracle so forgive me. My...
3
by: Thiko | last post by:
Hi I take one nightly full database backup at 02:00 and backup the transaction log to one backup set every 15mins. The commands to do this are as follows and are set up to run as database...
2
by: nt | last post by:
I am having a problem with a regular backup of an SQL Server (MSDE 2000) database to a local drive. I initiate the backup once a week, by issuing the required T-SQL, via ADO. In this case, the...
1
by: John Rajendran | last post by:
Hi there, I need to take a backup with the following scanerio in mind: At T1 I take the FULL BACK UP of the database called BACK_1_FULL.BACK in c:\ Then at T2 I would like to take only the...
6
by: Eric Herber | last post by:
I've a question regarding db2 (V8.1) and database backups going to a storage manager like TSM for example. As I can see in the storage manager if I backup the complete database over the TSM API...
1
by: alex | last post by:
Hi ! I couldn't make backups with our new system using db2 8.2. Every time I trigger a backup I get this error message: BACKUP DATABASE EBUERO2 ONLINE TO "/raid/backup/ebuero2/part1",...
4
by: uthuras | last post by:
Hi all, I have DB2ESE version 8.1 with FP 4 on AIX 5.2. My database used to be 1.1TB. When the DB size is 1.1TB, it takes approximately 7 hours to backup the entire database (online backup). The...
6
by: k04jg02 | last post by:
Problem: I have a properties dialog. X objects build the dialog, but a subclass of X, such as Y, can add more options to the dialog for Y specific properties. I would like to write code for the...
10
by: Konstantin Andreev | last post by:
Hello. Some time ago I asked in this conference, - How to use an ONLINE BACKUP to restore database onto another system? - but got no answers. Therefore I can conclude it is not possible. But......
2
by: clilush | last post by:
I've been working with db2 8.2fp14 for over a year now and was wondering what is a "standard" way of doing a backup to provide 24/7 operations with disaster recovery capabilities? My thoughts were...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.