Over the next few days we are going to start the migration to a new forum application. I'm going to start with high post count and active users. You may receive an invitation to the new forums. It's not spam. It's just me trying to seed the user base. My goal is to open it up over the weekend.

Once we open the site we'll block registrations here. We should be open shortly on the new site.

SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

qman
Constraint Violating Yak Guru

USA
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;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();

visakh16
Very Important crosS Applying yaK Herder

India
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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000