executing sql inside ssis script task is not working
尝试在vb.net中执行sql语句(脚本任务ssis)。为此创建了连接,请求打开连接并执行并关闭(如下代码所示)。变量的值(包含sql 结果集)必须返回正确的计数,而不是一直返回 -1 ......知道你这样做了吗?似乎是查询没有执行?
如何使用下面的 vb 代码获得正确的计数值(请查看)
在 ssis 脚本任务中?
Public Sub Main()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | Dim fireAgain As Boolean = True Dim rowsAffected As Integer Dim sqlConn As System.Data.SqlClient.SqlConnection Dim sqlComm As System.Data.SqlClient.SqlCommand Dim cm As ConnectionManager = Dts.Connections("cnn") ''Retrive the reference to the managed Connections '' Request an open connection sqlConn = cm.AcquireConnection(Dts.Transaction) Dts.Events.FireInformation(0,"","Connection is:" + sqlConn.State.ToString(),"", 0, fireAgain) ''Do your work sqlComm = New System.Data.SqlClient.SqlCommand("SELECT COUNT(*) AS CNT FROM [Table_1]", sqlConn) rowsAffected = sqlComm.ExecuteNonQuery() MsgBox(rowsAffected.ToString()) '''' the value of variable is -1 ??? ''Inform SSIS you're done your work cm.ReleaseConnection(sqlConn) Dts.Events.FireInformation(0,"", rowsAffected.ToString() +" rows updated.","", 0, fireAgain) End Sub |
谢谢
当您使用
要从查询中读取结果,请使用
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
如果您的查询返回多个单元格,请使用
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.aspx
对于您要实现的目标,您应该使用