Connect to SQL database inside Script Task in SSIS

前端 未结 2 869
抹茶落季
抹茶落季 2020-12-28 17:59

Inside of a Script Task in SSIS, I need to make a call to an SQL database. I have a connection string that was created when I added the database to the data sources folder,

相关标签:
2条回答
  • 2020-12-28 18:23

    You must check the privider of the connection that your are trying to instantiate.

    You can't cast a OleDb.OleDbConnection connection as a SQLClient.SQLConnection, the parameters are different.

    0 讨论(0)
  • 2020-12-28 18:27

    you cant use the configurations from a connection manager from inside a script task like: conectionManager1.exceuteSQLStatment(...)

    once you are "inside" the script task you need to access the CM like a variable:

    ConnectionManager cm;
    System.Data.SqlClient.SqlConnection sqlConn;
    System.Data.SqlClient.SqlCommand sqlComm;
    
    cm = Dts.Connections["conectionManager1"];
    
    sqlConn = (System.Data.SqlClient.SqlConnection)cm.AcquireConnection(Dts.Transaction);
    sqlComm = new System.Data.SqlClient.SqlCommand("your SQL Command", sqlConn);
    sqlComm.ExecuteNonQuery();
    
    cm.ReleaseConnection(sqlConn);
    
    0 讨论(0)
提交回复
热议问题