SQL Server – Best Way to Convert DTSX Packages to Query a New Server

sql server

We just moved our sql server to a hosting company, and now all my dtsx packaged don't work.

I know that in a specific query you can use

    use SecondDatabase

but is there a way to do that with the server, too?

Goal: Not have to rewrite my code and paste [eih-dr01.db.org].livendb.dbo. infront of every table.

Best Answer

Two options come to mind:

If your dtsx packages are stored in the file system, you could use POWERSHELL to read in each file, search and replace the connection string and rewrite the file. Here is an example:

(Make sure you make a copy of the folder BEFORE running the Powershell script, just in case):

$DtsxFiles = Get-ChildItem C:\Users\uswsh\Documents\*.dtsx -rec
foreach ($file in $DtsxFiles)
{
    (Get-Content $file.PSPath) |
    Foreach-Object { $_ -replace "localhost", "localhost1" } |
    Set-Content $file.PSPath
}

If your packages are not stored in the file system, you could dynamically generate CREATE SYNONYM commands that would point to the new location.

CREATE SYNONYM [dbo].[OriginalTable] FOR [RemoteServer].[RemoteDatabase].[RemoteSchema].[RemoteTable]