Please start any new threads on our new site at http://forums.sqlteam.com. 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
 
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
 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  
 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