Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Transaction object not associated with a Connection object
Message
From
10/11/2003 13:33:53
Rex Mahel
Realm Software, Llc
Ohio, United States
 
 
To
All
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Transaction object not associated with a Connection object
Miscellaneous
Thread ID:
00848434
Message ID:
00848434
Views:
243
All,

I have a user control with the following methods:
	Public WriteOnly Property strConnection() As String
		Set(ByVal Value As String)
			_strConnection = Value
			_objConnection = New OracleConnection(Value)
		End Set
	End Property


	Function LoadDataAdapter() As Boolean
		_objDataAdapter = New OracleDataAdapter()

		With _objDataAdapter
			.SelectCommand = New OracleCommand()
			With .SelectCommand
				.CommandText="pkg_service_provided.list_for_ifsp_id"
				.CommandType = CommandType.StoredProcedure
				.Connection = _objConnection
				With .Parameters
					.Add("P_IFSP_ID", OracleType.Int32)
					.Add("P_CURSOR", OracleType.Cursor)
				End With
				.Parameters("P_CURSOR").Direction = ParameterDirection.Output
			End With

			.InsertCommand = New OracleCommand()
			With .InsertCommand
				.CommandText = "pkg_service_provided.add"
				.CommandType = CommandType.StoredProcedure
				.Connection = _objConnection
				With .Parameters
					.Add("p_ifsp_id", OracleType.Int32, 4, "ifsp_id")
					.Add("p_service_type_id", OracleType.Int32, 4, "service_type_id")
					.Add("p_service_provider_type_id", OracleType.Int32, 4, "service_provider_type_id")
					.Add("p_service_provider_id", OracleType.Int32, 4, "service_provider_id")
					.Add("p_payment_source_id", OracleType.Int32, 4, "payment_source_id")
					.Add("p_user_id", OracleType.VarChar, 10, "user_id")
				End With
			End With
			.DeleteCommand = New OracleCommand()
			With .DeleteCommand
				.CommandText = "p_service_provided.delete"
				.CommandType = CommandType.StoredProcedure
				.Connection = _objConnection
				With .Parameters
					.Add("p_service_provided_id", OracleType.Int32, 4, "service_provided_id")
				End With
			End With
		End With
		Session.Add("MyDataAdapter", _objDataAdapter)
	End Function



	Function Save(ByVal intIFSPIdSave As Integer) As Boolean
		Dim dtDataTable As DataTable = CType(Session("MyDataGrid"), DataTable)
		Dim strUserId As String = us.RoleName
		Dim drDataRow As DataRow
		Dim intRows As Integer

		For Each drDataRow In dtDataTable.Rows
			drDataRow("ifsp_id") = intIFSPIdSave
			drDataRow("user_id") = strUserId
		Next

		_objDataAdapter = CType(Session("MyDataAdapter"), OracleDataAdapter)

		With _objDataAdapter
			Try
				_objConnection.Open()
				_objTransaction = _objConnection.BeginTransaction()
				.InsertCommand.Transaction = _objTransaction
				.DeleteCommand.Transaction = _objTransaction

				intRows = _objDataAdapter.Update(dtDataTable)
				dtDataTable.AcceptChanges()

				_objTransaction.Commit()
				Return True
			Catch eex As Exception
				_objTransaction.Rollback()
				Response.Write(eex.ToString())
				Return False
			Finally
				_objConnection.Close()
			End Try
		End With
	End Function
The LoadDataAdapter creates and populates the _objDataAdapter property which is cached. In the Save method, I create a Transaction object and set the Transaction property for the InsertCommand and the DeleteCommand, updates are not allowed, so no UpdateCommand. When the _objDataAdapter.Update is executed, I get the following message:

The Transaction object is not associated with the Connection object.

I have the _objConnection object created via the public property strConnection.
I use the _objConnection object to create the Command objects in the _objDataAdapter
I use the _objConnection object to create the _objTransaction object
I use the _objTransaction to set the Transaction property for the Insert and Delete Commands

At each step I see the association between the Connection object and the Transaction object.

What am I missing?

TIA

Rex
Next
Reply
Map
View

Click here to load this message in the networking platform