Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 718709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:33:30+00:00 2026-05-14T05:33:30+00:00

In SQL Server 2005 Integration Services, how can I automatically trigger a restoration of

  • 0

In SQL Server 2005 Integration Services, how can I automatically trigger a restoration of a transaction log backup file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:33:31+00:00Added an answer on May 14, 2026 at 5:33 am

    Just did a quick search and found this piece of T-SQL somewhere, just create a new ‘Execute SQL’ task in your package and give it a shot…

    ----------------------------------------------------------------------------------------
    -- Restore database from a backup file
    -- NOTE: If the database gets locked in Single user mode, execute 
    --       the below command on it and it will restore the Multiuser mode:
    --       ALTER DATABASE yourdatabasename SET MULTI_USER
    ---------------------------------------------------------------------------------------
    use master
    go
    
    declare @backupFileName varchar(100), @restoreDirectory varchar(100),
     @databaseDataFilename varchar(100), @databaseLogFilename varchar(100),
     @databaseDataFile varchar(100), @databaseLogFile varchar(100),
     @databaseName varchar(100), @execSql nvarchar(1000)
    
    -- Set the name of the database to restore
    set @databaseName = 'myDatabase'
    -- Set the path to the directory containing the database backup file.
    --IMPORTENT:: Make sure theer is a \ character at the end of your directory path below, else 
    -- the script will error out
    set @restoreDirectory = 'aboslute_path_to_restore_directory' -- such as 'c:\temp\'
    
    -- Create the backup file name based on the restore directory, the database name and today's date
    set @backupFileName = @restoreDirectory + @databaseName + '-' + replace(convert(varchar, getdate(), 110), '-', '.') + '.bak'
    
    -- Get the data file and its path
    select @databaseDataFile = rtrim([Name]),
     @databaseDataFilename = rtrim([Filename])
    from master.dbo.sysaltfiles as files
     inner join
     master.dbo.sysfilegroups as groups
     on
     files.groupID = groups.groupID
    where DBID = (
      select dbid
      from master.dbo.sysdatabases
      where [Name] = @databaseName
     )
    
    -- Get the log file and its path
    select @databaseLogFile = rtrim([Name]),
     @databaseLogFilename = rtrim([Filename])
    from master.dbo.sysaltfiles as files
    where DBID = (
      select dbid
      from master.dbo.sysdatabases
      where [Name] = @databaseName
     )
     and
     groupID = 0
    
    print 'Killing active connections to the "' + @databaseName + '" database'
    
    -- Create the sql to kill the active database connections
    set @execSql = ''
    select @execSql = @execSql + 'kill ' + convert(char(10), spid) + ' '
    from master.dbo.sysprocesses
    where db_name(dbid) = @databaseName
     and
     DBID <> 0
     and
     spid <> @@spid
    exec (@execSql)
    
    print 'Restoring "' + @databaseName + '" database from "' + @backupFileName + '" with '
    print '  data file "' + @databaseDataFile + '" located at "' + @databaseDataFilename + '"'
    print '  log file "' + @databaseLogFile + '" located at "' + @databaseLogFilename + '"'
    
    set @execSql = '
    restore database [' + @databaseName + ']
    from disk = ''' + @backupFileName + '''
    with
      file = 1,
      move ''' + @databaseDataFile + ''' to ' + '''' + @databaseDataFilename + ''',
      move ''' + @databaseLogFile + ''' to ' + '''' + @databaseLogFilename + ''',
      norewind,
      nounload,
      replace'
    
    exec sp_executesql @execSql
    
    ---------------End of Restore script---------------------------------------
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Entity Framework designer is terrible - I've had the… May 14, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer If by "hijack" you meant sniff the packets then what… May 14, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer If you want two actions to be atomic, embed them… May 14, 2026 at 5:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.