MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

ESSENTIALS: Home | Tips | Search | Categories | Top 10 | Products | Authors | Blogs | Forums | Webcasts | Advertise | About
Scheduling Backups for SQL Server 2005 Express -

in Search

Scheduling Backups for SQL Server 2005 Express

Last post 08-08-2008 1:06 PM by Kendjr. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 02-07-2007 12:00 AM

    Scheduling Backups for SQL Server 2005 Express

    This post is related to this tip: Scheduling Backups for SQL Server 2005 Express

    http://www.mssqltips.com/tip.asp?tip=1174

  • 06-17-2008 8:32 AM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

     just wanted to point out that the stored process sp_executesql is not in SQL Server 2005 Express.  I've looked in the sp folder and nothing is there. 

  • 06-17-2008 6:53 PM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 45

    Re: Scheduling Backups for SQL Server 2005 Express

    This is stored under the Extended Stored Procedures -> System Extended Stored Procedures

    Try running this code below to see if this works:

     

    use master
    go

    sp_executesql N'SELECT * FROM sys.databases'

  • 06-21-2008 5:13 PM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

     Hello,

       I am very thankful to the code which i got it from you on taking the backup. I am a .net Programmer.

    I have an requirement as to take the backup on different paths (as you have gave "c:\Backup") the path will change any no. of time, so i am planning to send a parameter of path, i tried to run the stored proc as this. but this gives a problem.

    USE [master]
    GO
    /****** Object:  StoredProcedure [dbo].[sp_BackupDatabase]    Script Date: 06/22/2008 03:54:47 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO


    -- =============================================
    -- Author: Edgewood Solutions
    -- Create date: 2007-02-07
    -- Description: Backup Database
    -- Parameter1: databaseName
    -- Parameter2: backupType F=full, D=differential, L=log
    -- =============================================
    alter PROCEDURE [dbo].[sp_BackupDatabasess] 
           @databaseName sysname, @backupType CHAR(1),
           @backuppath varchar(200)
    AS
    BEGIN
           SET NOCOUNT ON;

           DECLARE @sqlCommand NVARCHAR(1000)
           DECLARE @dateTime NVARCHAR(20)

           SELECT @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),111),'/','') +
           REPLACE(CONVERT(VARCHAR, GETDATE(),108),':','') 

           IF @backupType = 'F'
                   SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName +
                   ' TO DISK = '+@backuppath + @databaseName + '_Full_' + @dateTime + '.BAK'''
           
           IF @backupType = 'D'
                   SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName +
                   ' TO DISK = '+@backuppath + @databaseName + '_Diff_' + @dateTime + '.BAK'' WITH DIFFERENTIAL'
           
           IF @backupType = 'L'
                   SET @sqlCommand = 'BACKUP LOG ' + @databaseName +
                   ' TO DISK = '+@backuppath + @databaseName + '_Log_' + @dateTime + '.TRN'''
           
           EXECUTE sp_executesql @sqlCommand
    END

     

     

    Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near 'c:'.
    Msg 105, Level 15, State 1, Line 1
    Unclosed quotation mark after the character string ''.

     

    I would be very glad, if you can help me. prashanthganathe@gmail.com.

     

    Thanks & Regards,

    prashanthganathe@gmail.com.

     

     

  • 06-23-2008 6:35 AM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 45

    Re: Scheduling Backups for SQL Server 2005 Express

    You need to fix the quoting around the path.

    The line should be like this

           IF @backupType = 'F'
                   SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName +
                   ' TO DISK = '''+@backuppath + @databaseName + '_Full_' + @dateTime + '.BAK'''

     

    You need to  have three single quotes before the @backuppath variable

  • 06-25-2008 6:26 AM In reply to

    • proof
    • Top 500 Contributor
    • Joined on 06-25-2008
    • Posts 1

    Re: Scheduling Backups for SQL Server 2005 Express

    I love this script, but how would Iike to use it to backup another database, that may have users in it at the time.  Is there a way to run this script to an attached database that may be active?

  • 07-02-2008 4:14 PM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

     This script also needs brackets eg: [ ] around the database name to support names with characters such as hyphens ( - )

  • 08-08-2008 10:24 AM In reply to

    • Kendjr
    • Top 150 Contributor
    • Joined on 08-08-2008
    • Posts 2

    Re: Scheduling Backups for SQL Server 2005 Express

    I am using VIsta, and I am receiving the following error:

    Cannot open backup device 'C:\Users\Ken\Documents\Backup\SQL Goldmine Backups\Princeton3_Full_20080808131951.BAK'. Operating system error 5(Access is denied.).

    Can you tell me where I can open up the access?

    Thanks,

    Ken

  • 08-08-2008 12:51 PM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 45

    Re: Scheduling Backups for SQL Server 2005 Express

    This is a permissions problem.  The SQL Server service account probably does not have rights to the folder where you are trying to create the backup files. 

    By default the NetworkService account is probalby being used for SQL Express which has limited rights.

    You can either grant rights to this account to create files in this folder or you can use a different account for the SQL Server service or write to a folder where this account has permissions to create files.

  • 08-08-2008 1:06 PM In reply to

    • Kendjr
    • Top 150 Contributor
    • Joined on 08-08-2008
    • Posts 2

    Re: Scheduling Backups for SQL Server 2005 Express

    Thanks,

     I am not familiar with any of these, what would you recommend doing, and how can I do that?

     Thank you very much for your help.

     Ken

Page 1 of 1 (10 items)