SQL Server Development Bookmark and Share   
 index > SQL Server Integration Services > Getting connection info in a script task - how?
 

Getting connection info in a script task - how?

Greetings,

I have the following information in my package configuaration file:

<Configuration ConfiguredType="Property" Path="\Package.Connections[SMTP Connection Manager - ESIWP1MG1].Properties[SmtpServer]" ValueType="String">

<ConfiguredValue>10.120.1.36</ConfiguredValue>

</Configuration>

There isn't a variable in my package corresponding to the connection info - the value in the configuration file was created from an SMTP connection I created. (I exported the value when I created the Xml configuration file.)

I need to access the property value(10.120.1.36) within a script task but I don't know how to do this. Can someone provide the syntax for accessing the value? Do I need to create a variable to make this work?

Thanks...
BlackCatBone  Monday, July 28, 2008 3:52 PM

The "correct" way to use a connection at runtime is to retrieve it from the connections collection, and call the AcquireConnection method. This gives you a valid connection object.

In the case of the SMTP Connection that object is actually a string, the connection string, e.g. SmtpServer=mail.domain.net;UseWindowsAuthentication=True;EnableSsl=False;

Code Snippet

' Get the SMTP connection, the result is string rather than a actual SMTP connection type

Dim smtpConnectionAsString As String = CType(Dts.Connections("SMTP Connection Manager").AcquireConnection(Nothing), String)

You can take the more direct approach, and to be honest it will work, and just retrieve the SMTP Server property directly, e.g. mail.domain.net

Code Snippet

' Get the SMTP connection's server property value

Dim smtpConnectionManager As ConnectionManager = Dts.Connections("SMTP Connection Manager")

Dim smtpServer As String = CType(smtpConnectionManager.Properties("SmtpServer").GetValue(smtpConnectionManager), String)

Darren Green SQLIS  Monday, July 28, 2008 4:50 PM

The "correct" way to use a connection at runtime is to retrieve it from the connections collection, and call the AcquireConnection method. This gives you a valid connection object.

In the case of the SMTP Connection that object is actually a string, the connection string, e.g. SmtpServer=mail.domain.net;UseWindowsAuthentication=True;EnableSsl=False;

Code Snippet

' Get the SMTP connection, the result is string rather than a actual SMTP connection type

Dim smtpConnectionAsString As String = CType(Dts.Connections("SMTP Connection Manager").AcquireConnection(Nothing), String)

You can take the more direct approach, and to be honest it will work, and just retrieve the SMTP Server property directly, e.g. mail.domain.net

Code Snippet

' Get the SMTP connection's server property value

Dim smtpConnectionManager As ConnectionManager = Dts.Connections("SMTP Connection Manager")

Dim smtpServer As String = CType(smtpConnectionManager.Properties("SmtpServer").GetValue(smtpConnectionManager), String)

Darren Green SQLIS  Monday, July 28, 2008 4:50 PM

Merci beaucoup, Darren - it worked great

BCB

BlackCatBone  Monday, July 28, 2008 7:01 PM

You can use google to search for other answers

Custom Search

More Threads

• SQL Server 2005 SP3 CTP Now Available
• how to do a conditional split but make a copy of the rows rather than splitting?
• Script Task Error?
• Browse Button (...) is not available for a variable that is flagged to EvaluateAsExpression
• Temporary Table load in Data Flow
• Intra-query parallelism Error - Interesting Issue
• sp_add_jobstep MAXCONCURRENT - What parameter value is required to run a SSIS step synchronously - wtihin a schedule
• Using Access and SSIS Package
• "Microsoft OLE DB Provider for SQL Server" Hresult: 0x80004005
• Using SQL 2008 DLLs to enumerate sql 2000 dts packages