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)
 SQL Query within Script Task

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2014-03-03 : 11:03:44
I am trying to use a C# script task in order to insert records into a backend SQL table.

The task fails when it encounters the 4th line of code shown below. It fails when trying to create a new SqlConnection object passing in my connection as a string. I am assuming I need to convert the conString string to something.....


ConnectionManager cm;
cm = Dts.Connections["My SQL Connection Manager"];
String conString = cm.ConnectionString;
SqlConnection myConnection = new SqlConnection(conString);

String myInsertQuery = "INSERT INTO dbo.My_Table(A, B, C) VALUES('AAA', 'BBB', 'CCC')";

SqlCommand myCommand = new SqlCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-03-03 : 14:54:10
why do you need script task for this? Why not simply use execute sql task?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -