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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 SQL Query within Script Task
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

442 Posts

Posted - 03/03/2014 :  11:03:44  Show Profile  Reply with Quote
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;

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 03/03/2014 :  14:54:10  Show Profile  Reply with Quote
why do you need script task for this? Why not simply use execute sql task?

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000