Results 1 to 23 of 23

Thread: Need help with restoring the data using store procedure [resolved]

Hybrid View

  1. #1
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2004
    Posts
    610

    Re: Need help with restoring the data using store procedure

    i tried already
    earlier on
    but it cannot read 2 seperate parameters..

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Need help with restoring the data using store procedure

    Quote 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:
    1. myCommand.Parameters.Add(New SqlParameter("@Name", RestoreName)
    2. myCommand.Parameters.Add(New SqlParameter("@Path", RestorePath))

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width