"CAM"にデータを挿入した後、テーブル "CAM"とテーブル "COut"にデータを挿入する2つのテーブルがあり、 "COut"に手渡されるretAutoIDを返します。挿入に必要なパラメータの1つ。 "Cout"が挿入中に例外エラーに遭遇した場合、成功したとしても "CAM"の前の挿入がロールバックされるように、私はBusiness Logicでロールバックを実装しました。以下のコードでSQLトランザクションのロールバックエラー
、私は挿入を行うやろうとした後、このエラーを取得しています: 「のExecuteNonQueryは、コマンドに割り当てられ、接続が保留中のローカル・トランザクションであるときにトランザクションを持つようにコマンドを必要とするのTransactionプロパティ。コマンドは初期化されていません。
私は問題はに起因するかもしれないと思う:私、私は完全に "Coutに" の第二のデータの挿入を削除した場合
たDbCommand = GetStoredProcedureCommand( "COut_Add") dbCommand.Connection =のDBConnection
問題はありません。親切に助言してください。ありがとう。
Public Function InsertCM(ByVal objCMBLL As CMBLL, ByVal dbTrans As DbTransaction, ByVal dbConnection As DbConnection, ByVal COut As DataSet) As Boolean
Dim dbCommand As DbCommand = Nothing
Dim retAutoID As Int32 = Nothing
Dim bol_Success As Boolean = False
Try
If dbConnection.State <> ConnectionState.Open Then
dbConnection.Open()
End If
dbCommand = GetStoredProcedureCommand("CAM_Add")
dbCommand.Connection = dbConnection
dbCommand.Transaction = dbTrans
With objCMBLL
AddInParameter(dbCommand, "@Code", DbType.String, 50, DBNull.Value)
If Not String.IsNullOrEmpty(.CamCode) Then
dbCommand.Parameters("@Code").Value = .CamCode
End If
retAutoID = CType(ExecuteScalar(dbCommand), Integer)
dbCommand = GetStoredProcedureCommand("COut_Add")
dbCommand.Connection = dbConnection
For i As Integer = 0 To COut.Tables("COut").Rows.Count - 1
dbCommand.Parameters.Clear()
AddInParameter(dbCommand, "@Ol_Code", DbType.String, 50, DBNull.Value)$
dbCommand.Parameters("@Ol_Code").Value = COut.Tables("CampaignOutlets").Rows(i).Item(0).ToString
AddInParameter(dbCommand, "@Campaign_AutoID", DbType.Int32, 0, DBNull.Value)
dbCommand.Parameters("@Campaign_AutoID").Value = retAutoID
Next i
ExecuteNonQuery(dbCommand)
End With
bol_Success = True
Catch ex As Exception
Throw New DALException(ex, dbCommand, Caching.GetCustomerCodeCookie(), "InsertCampaignManagementTable")
Finally
If Not dbCommand Is Nothing Then
dbCommand.Dispose()
End If
End Try
Return bol_Success
End Function
どのデータベースですか? –
渡したdbTransは、dbConnectionのトランザクションではありませんか? – Carth