I don't remember the link where I found this. but it woks! (only you have to change to C# or find the way to put in VB it coud be easy)
SSIS has problems with cast Object_COM to IDTSConnectionManager
, I wasted a lot of time with it, so OleDbConnection
fix it.
Using your Connection Manager and the name of the connection OLEDB_NameConnectionTo_SQLServer
,
if you use storesProcedures
or function in the query the character "?" is important to put the parameters after, I really don't know why so off the hook
you have to add this refences.
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Data.OleDb;
...
try{
ConnectionManager cm = Dts.Connections["OLEDB_NameConnectionTo_SQLServer"];
IDTSConnectionManagerDatabaseParameters100 cmParams = cm.InnerObject as IDTSConnectionManagerDatabaseParameters100;
OleDbConnection conn = cmParams.GetConnectionForSchema() as OleDbConnection;
OleDbCommand cmd = new OleDbCommand("EXEC SP ?, ?, ?;", conn);
OleDbParameter Param = cmd.Parameters.Add("@PIParam", OleDbType.Integer);
ParametroId.Value = 3;
OleDbParameter Cons = cmd.Parameters.Add("@PICons", OleDbType.Integer);
Cons.Value = 2;
OleDbParameter Cte = cmd.Parameters.Add("@PICte", OleDbType.Integer);
Cte.Value = 1;
using ( OleDbDataReader reader = cmd.ExecuteReader() ){
if ( reader.HasRows && reader.Read() )
valor = (reader["VALUE"].ToString());
}
cm.ReleaseConnection(conn);
} catch( Exception ex ){
MessageBox.Show(ex.Message.ToString());
}