vb.net (スクリプト タスク ssis) 内で SQL ステートメントを実行しようとしています。このために、接続を作成し、開いた接続を要求し、実行して閉じました (以下のコードに示すように)。変数の値 (SQL の結果を保持します) set) は、常に -1 を返す代わりに、正しいカウントを返す必要があります...そうする考えはありますか?クエリが実行されていないようです?
ssis スクリプト タスクで以下の vb コードを使用して正しいカウント値を取得するにはどうすればよいですか (ご覧ください)。
パブリック サブ メイン()
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
ありがとう