Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Calling SP From Script Task Using C#

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2011-10-03 : 09:33:19
I am trying to call a SP from within a Script Task using C#, SQL Server 2008. My code blows up when I attempt to create a new SQLConnection using a .NET connection string/manager. Can someone help me out with the proper format using a connection manager as the SQL Connection? Also, could someone show me how to assign the result set (multiple rows) to a variable to be used later?

public void Main(){

myresultsetvariable string;

SqlConnection sqlconn = new SqlConnection("MY_DOTNET_CON_MANAGER");
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = sqlconn;
sqlcmd.CommandText = "dbo.stp_MY_SP_NAME";
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("Parm1", DbType.String).Value = "AA";
sqlcmd.Parameters.AddWithValue("Parm2", DbType.String).Value = "BB";

sqlcmd.ExecuteNonQuery();
sqlconn.Close();
Dts.TaskResult = (int)ScriptResults.Success;
}
   

- Advertisement -