The transaction is either not associated with the current connection or has been completed.
#Region "Database Queries"
Private Shared oSqlConnection As SqlConnection
Private Shared oSqlDataAdapter As SqlDataAdapter
Private Shared oSqlCommand As SqlCommand
Private Shared oSqlTransaction As SqlTransaction
Private Shared _strCommand As String
Public Shared Property strCommand() As String
Get
Return _strCommand
End Get
Set(ByVal value As String)
If Not InTransaction Then RollBack_Transaction()
_strCommand = "SET DATEFORMAT mdy " & vbCrLf & value
DbQuery()
End Set
End Property
Protected Shared Sub DbQuery()
'Try
If Not InTransaction Then
RollBack_Transaction()
oSqlCommand = New SqlCommand(_strCommand, oSqlConnection)
Else
oSqlCommand = oSqlConnection.CreateCommand
If _InTransaction_Initial Then
oSqlConnection.Open()
oSqlTransaction = oSqlConnection.BeginTransaction(IsolationLevel.ReadCommitted)
_InTransaction_Initial = False
End If
oSqlCommand.Transaction = oSqlTransaction
oSqlCommand.CommandText = _strCommand
oSqlCommand.CommandTimeout = 0
End If
oSqlDataAdapter = New SqlDataAdapter(oSqlCommand)
Ds = New DataSet
oSqlDataAdapter.Fill(Ds) '<- - - The error occurs here'
'Catch ex As Exception
' SetMessage(ex)
' ' MsgBox("Server: " & ServerName & vbCrLf & "User Id: " & SqlID & vbCrLf & "Password: " & SqlPassword & vbCrLf & "Database: " & MainDb)
'End Try
'oSqlConnection.Close()
End Sub
Private Shared _InTransaction_Initial As Boolean = False
Private Shared InTransaction As Boolean
Public Shared Sub StartTransaction()
_InTransaction_Initial = True
InTransaction = True
End Sub
Public Shared Sub RollBack_Transaction()
Try
oSqlTransaction.Rollback()
Catch ex As Exception
End Try
Try
oSqlConnection.Close()
Catch ex As Exception
End Try
InTransaction = False
End Sub
Public Shared Sub Commit_Transaction()
Try
oSqlTransaction.Commit()
Catch ex As Exception
End Try
Try
oSqlConnection.Close()
Catch ex As Exception
End Try
InTransaction = False
End Sub
Function dsCount() As Long
Return Ds.Tables(0).Rows.Count
End Function
#End Region
Look like the problem because you call open() in if condition and fill ds outside this condition.
If _InTransaction_Initial Then
oSqlConnection.Open()
End If
How do you fill ds in false condition?
Hi,
If _InTransaction_Initial is True, it means that I used the StartTransaction function.
So, in the first run of the transaction. The _InTransaction_Initial will set to False.
I have a scenario that, I open two browser and get specific document(eg. 1 and 5) to submit, and trigger the submit button at the same time. Then this error occur.
But if I delay or give interval before submitting, I didn't encounter this error. Maybe like 2sec interval before submitting the second document. Any idea with this?
Below is my code for submit.
StartTransaction()
If GetByAppId(AppId.Text) Then
If Not Submit Then
Goto RollBack
End If
Else
RollBack:
Rollback_Transaction
Return
End If
Commit_Transaction()
Hi experts. I need your help badly. I have 15 users that are simultaneous posting, updating transactions. And this error occured. Any other suggestions? Is there any setup in database that can handle more than 15users when connecting?
hikaru1207
Member
1 Points
17 Posts
Error in my WEB APP
Feb 28, 2013 01:25 AM|LINK
Hi experts,
Still having this error in my web app.
The transaction is either not associated with the current connection or has been completed.
#Region "Database Queries" Private Shared oSqlConnection As SqlConnection Private Shared oSqlDataAdapter As SqlDataAdapter Private Shared oSqlCommand As SqlCommand Private Shared oSqlTransaction As SqlTransaction Private Shared _strCommand As String Public Shared Property strCommand() As String Get Return _strCommand End Get Set(ByVal value As String) If Not InTransaction Then RollBack_Transaction() _strCommand = "SET DATEFORMAT mdy " & vbCrLf & value DbQuery() End Set End Property Protected Shared Sub DbQuery() 'Try If Not InTransaction Then RollBack_Transaction() oSqlCommand = New SqlCommand(_strCommand, oSqlConnection) Else oSqlCommand = oSqlConnection.CreateCommand If _InTransaction_Initial Then oSqlConnection.Open() oSqlTransaction = oSqlConnection.BeginTransaction(IsolationLevel.ReadCommitted) _InTransaction_Initial = False End If oSqlCommand.Transaction = oSqlTransaction oSqlCommand.CommandText = _strCommand oSqlCommand.CommandTimeout = 0 End If oSqlDataAdapter = New SqlDataAdapter(oSqlCommand) Ds = New DataSet oSqlDataAdapter.Fill(Ds) '<- - - The error occurs here' 'Catch ex As Exception ' SetMessage(ex) ' ' MsgBox("Server: " & ServerName & vbCrLf & "User Id: " & SqlID & vbCrLf & "Password: " & SqlPassword & vbCrLf & "Database: " & MainDb) 'End Try 'oSqlConnection.Close() End Sub Private Shared _InTransaction_Initial As Boolean = False Private Shared InTransaction As Boolean Public Shared Sub StartTransaction() _InTransaction_Initial = True InTransaction = True End Sub Public Shared Sub RollBack_Transaction() Try oSqlTransaction.Rollback() Catch ex As Exception End Try Try oSqlConnection.Close() Catch ex As Exception End Try InTransaction = False End Sub Public Shared Sub Commit_Transaction() Try oSqlTransaction.Commit() Catch ex As Exception End Try Try oSqlConnection.Close() Catch ex As Exception End Try InTransaction = False End Sub Function dsCount() As Long Return Ds.Tables(0).Rows.Count End Function #End RegionPlease see the Bold text in the code.
Hope to hear positive response from you.
Regards,
hikaru1207
Member
1 Points
17 Posts
Re: Error in my WEB APP
Mar 13, 2013 03:17 AM|LINK
Please help.
oned_gk
All-Star
31766 Points
6492 Posts
Re: Error in my WEB APP
Mar 19, 2013 03:58 AM|LINK
Look like the problem because you call open() in if condition and fill ds outside this condition.
If _InTransaction_Initial Then oSqlConnection.Open() End IfHow do you fill ds in false condition?
hikaru1207
Member
1 Points
17 Posts
Re: Error in my WEB APP
Mar 19, 2013 11:55 AM|LINK
Hi,
If _InTransaction_Initial is True, it means that I used the StartTransaction function.
So, in the first run of the transaction. The _InTransaction_Initial will set to False.
I have a scenario that, I open two browser and get specific document(eg. 1 and 5) to submit, and trigger the submit button at the same time. Then this error occur.
But if I delay or give interval before submitting, I didn't encounter this error. Maybe like 2sec interval before submitting the second document. Any idea with this?
Below is my code for submit.
Regards,
hikaru1207
Member
1 Points
17 Posts
Re: Error in my WEB APP
Mar 21, 2013 09:43 AM|LINK
Hi experts. I need your help badly. I have 15 users that are simultaneous posting, updating transactions. And this error occured. Any other suggestions? Is there any setup in database that can handle more than 15users when connecting?