Friday, April 13, 2018

SQL commands colliding between users, while clicking a button at the same time, ASP.NET 4.5 WebForms VB

I have taken on a legacy project at my current job, and it is a ASP.net 4.5 WebForms application running on a Windows Server 2008 R2, with a SQL Server 2008 R2 database behind it.

Currently we have an issue where if two or more users click on a button that executes a SQL Command they get one of two errors:

"A severe error occurred on the current command. The results, if any, should be discarded."

or

"ExecuteReader requires an open and available Connection. The connection's current state is open."

The first issue can be cleared up if the user refreshes, the second issue requires the AppPool to be recycled on the web server.

Here is an example of a call to the database:

Public Function OpenSQLConn() As String If SQLConn.State = ConnectionState.Closed Then SQLConn.ConnectionString = ConnStr SQLConn.Open() End If OpenSQLConn = SQLConn.DataSource.ToString End Function Public Function CloseSQLConn() As String If SQLConn.State = ConnectionState.Open Then SQLConn.Close() End If CloseSQLConn = SQLConn.Database.ToString End Function Public Sub getDataSet(ByRef ds As DataSet, ByVal dataTable As String, ByVal queryString As String) OpenSQLConn() Dim sqlCmd As New SqlCommand With sqlCmd .CommandText = queryString .CommandTimeout = 0 .CommandType = CommandType.Text .Connection = SQLConn End With Dim da As New SqlDataAdapter(sqlCmd) da.Fill(ds, dataTable) CloseSQLConn() End Sub Public Function executeSQL(ByVal queryString As String, Optional ByVal doNotExecuteDebugOnly As Boolean = False) As Boolean If SQLConn.ConnectionString = "" Then SQLConn.ConnectionString = ConnStr End If If doNotExecuteDebugOnly = True Then Debug.Print("ExecuteSQL, Not Executed: " & queryString) End If Dim da As New SqlDataAdapter(queryString, SQLConn) Dim ds As New DataSet If SQLConn.State = ConnectionState.Closed Then SQLConn.Open() End If da.Fill(ds, "temp") executeSQL = True SQLConn.Close() End Function 

I'm assuming I need to change the way I am accessing SQL, or do something different with the settings on the Servers, but I'm at a loss as to what to change. Any thing would be helpful at this point.

SQL commands colliding between users, while clicking a button at the same time, ASP.NET 4.5 WebForms VB Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team