Using an Existing Connection in a Script Component (SSIS)

I have an OLEDB Connection configured in connection managers and I want to use it in SCRIPT. The script needs to call the stored proc, and then create the buffer lines. I added a connection to the connections available for the script, and this is my code.

Boolean fireagain = true;

SqlConnection conn = new SqlConnection();

conn = (SqlConnection)(Connections.Connection
    .AcquireConnection(null) as SqlConnection);


SqlCommand cmd = new SqlCommand();

conn.Open();

ComponentMetaData.FireInformation(
           0, "Script", "Connection Open", string.Empty, 0, ref fireagain);

cmd.Connection = conn;
cmd.CommandText = "up_FullTextParser_select" ;
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("Phrase", DbType.String).Value = Row.Keywords;
cmd.Parameters.AddWithValue("SpecialTerm", DbType.String).Value = "Exact match";
cmd.Parameters.AddWithValue("StopListId", DbType.Int32).Value = 0;
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

while (rdr.Read())
{
    TermsBuffer.AddRow();

    TermsBuffer.Term = rdr[0].ToString();
}

conn.Close();

Anyway, it doesn't seem to work on AcquireConnection. Am I doing this wrong? Should I use a different way of using connections defined outside the script ?.

+3
source share
4 answers

MSDN AcquireConnection.

+1

.

+1

OLEDB, AcquireConnection, , OLEDB:

string connstr = Dts.Connections["my_OLEDB_connection"].ConnectionString;
System.Data.OleDb.OleDbConnection objConn = new System.Data.OleDb.OleDbConnection(connstr);   

, - .

+1
source

Source: https://habr.com/ru/post/1733167/


All Articles