|
-
Mar 4th, 2005, 09:39 AM
#1
Re: Need help with restoring the data using store procedure
I've not done .NET work - but I believe you need to break that parameter line into two lines. Processing one parameter at a time.
-
Mar 4th, 2005, 01:17 PM
#2
Thread Starter
Fanatic Member
Re: Need help with restoring the data using store procedure
i tried already
earlier on
but it cannot read 2 seperate parameters..
-
Mar 4th, 2005, 01:54 PM
#3
Re: Need help with restoring the data using store procedure
 Originally Posted by ryanlum
i tried already
earlier on
but it cannot read 2 seperate parameters..
Ummm.... that doesn't make sense..... sure it can, I did so just last night....
In fact....
VB Code:
myCommand.Parameters.Add(New SqlParameter("@Name", RestoreName)
myCommand.Parameters.Add(New SqlParameter("@Path", RestorePath))
Tg
-
Mar 4th, 2005, 02:00 PM
#4
Re: Need help with restoring the data using store procedure
You know - we went around and around the other day (in your other thread) with what can and cannot be a variable in a SPROC.
Here is a BACKUP command that I use:
Code:
BACKUP DATABASE Funds
TO DISK = 'c:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Funds_copy.bak'
Notice that the c:\Program Files... stuff is in QUOTES. That means it's a string. That means you can replace it with a variable.
This will work - and we talked about it in your other thread:
Code:
Declare @Location varchar(100)
Set @Location='c:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Funds_copy.bak'
Backup Database Funds to Disk = @Location
The only reason that works is that @Location is a variable, replacing a "string" in a command.
But - the first three words in the backup command - Backup Database Funds are not string. They are keywords.
I do not believe that you will be able to use a variable for the database name.
You should test that in QA before trying to make a jump all the way to production calls of a SPROC that won't work anyway. Otherwise you will find yourself going around in the same circles as the other day.
If you have a dozen different databases - you can create an IF/BEGIN/END block for each one in the SPROC - that will allow you to have a parameterized database name.
-
Mar 4th, 2005, 02:54 PM
#5
Re: Need help with restoring the data using store procedure
I'm going to go waaaaay out on a limb here and suggest something..... it may bite me in the arse, and if I get it wrong szlamany, plz correct me. But....
Would this work?
DECLARE @DBName as sql_variant
SET @DBName = N'MyDB'
BACKUP DATABASE @DBName
TO DISK = 'c:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\Funds_copy.bak'
??
I'm just asking. Personaly, I'd do my backup another way, especialy if they need to be dynamic like that.
Additionaly, could such a query be executed via dynamic SQL using EXEC?
Tg
-
Mar 4th, 2005, 03:10 PM
#6
Re: Need help with restoring the data using store procedure
TG - I stand corrected. I wasn't 100% sure either way - just wanted to make sure the person tested in QA before launching into VB to call it.
All three of these backup statements worked:
Code:
backup database acctfiles to disk='c:\a1.bak'
go
declare @d1 varchar(100)
set @d1='c:\a2.bak'
backup database acctfiles to disk=@d1
go
declare @db varchar(100)
declare @d1 varchar(100)
set @db='acctfiles'
set @d1='c:\a3.bak'
backup database @db to disk=@d1
go
Code:
Message pane looked like this:
Processed 13824 pages for database 'acctfiles', file 'Acctfiles_Data' on file 1.
Processed 1 pages for database 'acctfiles', file 'Acctfiles_Log' on file 1.
BACKUP DATABASE successfully processed 13825 pages in 4.665 seconds (24.275 MB/sec).
Processed 13824 pages for database 'acctfiles', file 'Acctfiles_Data' on file 1.
Processed 1 pages for database 'acctfiles', file 'Acctfiles_Log' on file 1.
BACKUP DATABASE successfully processed 13825 pages in 6.633 seconds (17.073 MB/sec).
Processed 13824 pages for database 'acctfiles', file 'Acctfiles_Data' on file 1.
Processed 1 pages for database 'acctfiles', file 'Acctfiles_Log' on file 1.
BACKUP DATABASE successfully processed 13825 pages in 6.685 seconds (16.940 MB/sec).
Syntax wise that makes no sense to me. You can't have a variable for the "SELECT" keyword.
-
Mar 4th, 2005, 03:11 PM
#7
Re: Need help with restoring the data using store procedure
But this doesn't work:
Code:
declare @what varchar(100)
declare @db varchar(100)
declare @d1 varchar(100)
set @what = 'database'
set @db='acctfiles'
set @d1='c:\a3.bak'
backup @what @db to disk=@d1
go
Which makes sense - since "database" is keyword - not in quotes. So the syntax allows the unquoted database name or a variable - that's odd to me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|