Home > SSIS > Get ConnectionString from Connection manager – SSIS

Get ConnectionString from Connection manager – SSIS


Connection string building is vital task for programmer to connect to a database server in Script Task. of course, there is a website that has pre-defined connection strings for all database servers. You can browse connectionStrings here.

But, In this article I will show you how to read the connection string from the connection manager in script task.

Step 1: Create a SSIS package

Step 2: Add a OLE DB connection and connect to your Microsoft SQL Server server.

 

 

 

 

 

 

Step 3: Add a script task and go to script window and the following code.

Public Sub Main()

‘ Add your code here
‘ Statement to get connection string
MsgBox(Dts.Connections(“MyConnection”).ConnectionString)

Dts.TaskResult = ScriptResults.Success
End Sub

Step 4: execute the package

 

 

 

Thanks for reading.

Advertisements
  1. César Betancurth
    February 1, 2017 at 2:50 pm

    First thanks for the post, it was very useful.

    In the next script you can find the code upgrade to Visual Studio 2008.

    public void Main()
    {
    // TODO: Add your code here
    Dts.Connections.ToString();
    MessageBox.Show(Dts.Connections[“MyConnection”].ConnectionString);
    Dts.TaskResult = (int)ScriptResults.Success;

    }

  2. César Betancurth
    February 1, 2017 at 2:51 pm

    First thanks for the post, it was very useful.

    In the next script you can find the code upgrade to Visual Studio 2008.

    public void Main()
    {
    // TODO: Add your code here
    Dts.Connections.ToString();
    MessageBox.Show(Dts.Connections[“MyConnection”].ConnectionString);
    Dts.TaskResult = (int)ScriptResults.Success;

    }

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: