I need to connect to SQL Server db through a script task to fill in DataTable, I use the ADO.Net provider / connection. However, for life, I get all kinds of errors. For example, when using it, SqlAdapterI get an invalid object error, however, it SqlCommandruns without errors in SSMS:
SqlConnection conn;
ConnectionManager cm;
SqlCommand cmd;
cm = Dts.Connections["AdoNet"];
conn = (SqlConnection)cm.AcquireConnection(Dts.Transaction);
using (conn)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = queryString;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(myDataTable);
}
source
share