Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataReader is already opened
Message
 
 
To
16/08/2010 12:05:29
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01476630
Message ID:
01476639
Views:
34
The code is a bit complex for me to understand, but can you re-write it with USING statements or call loDataProvider.Close() -- (or Dispose()) after you done?



>>Can you post more code, please? How do you declare DataReader and do you close it when done?
>
>In a desktop environment, the connection is opened at startup and remains as is as long as the application runs.
>
>When a request is necessary on SQL Server, I declare a data provider object. That data provider object lives for the duration of the command.
>
>
>        Dim loDataProvider As Framework.Framework.Data = New Framework.Framework.Data(oApp)
>
>        ' We have to get the primary key
>        loDataProvider.ParameterAdd("Numero", nRobotPrimaryKey)
>        If Not loDataProvider.SQLExec("SELECT Robot.NoServer,Robot.Run " + _
>         "FROM Robot " + _
>         "WHERE Robot.Numero=" + loDataProvider.ParameterAddSQL("Numero")) Then
>            CloseForm()
>        End If
>
>
>This code is the first section of code and the first access to the data which is done every minute. So, once loDataProvider.SQLExec() is executed, my loDataProvider is clean.
>
>The top portion of code in the SQLExec() method is:
>
>
>        ' SQL exec
>        ' expC1 SQL command
>        Public Function SQLExec(ByVal tcSQL As String) As Boolean
>            Dim lcCharacter As String = ""
>            Dim lcCommandText As String = ""
>            Dim lcField As String = ""
>            Dim lcString As String = ""
>            Dim lcTable As String = ""
>            Dim llSuccess As Boolean = False
>            Dim lnCounter As Integer = 0
>            Dim lnLocation As Integer = 0
>            Dim lnLocation2 As Integer = 0
>            Dim lnOccurence As Integer = 0
>            Dim lnDateNow As Double = 0
>            Dim lnDateNow2 As Double = 0
>            Dim lnElapse As Double = 0
>            Dim loColumn As DataColumnCollection
>            Dim loDataParameterSQLClient As SqlParameter = Nothing
>            Dim loInsertRow As Framework.InsertRow
>            Dim loObject As Object
>
>            ' Reset the duration value
>            nDuration = 0
>
>            If Not InitializeDataObject(tcSQL) Then
>                Return False
>            End If
>
>
>The InitializeDataObject() method, which is where I believe the error occured is simply establishing the connection:
>
>
>        Private Function InitializeDataObject(ByVal tcSql As String) As Boolean
>            Dim lcType As String = ""
>
>            ' Connection object to be used when we have to open the connection manually
>            Dim loConnection As IDbConnection = Nothing
>
>            Dim loDataParameterSQLClient As SqlParameter = Nothing
>            Dim loEnumerator As IEnumerator = oParameters.GetEnumerator
>            Dim loParameter As Object
>
>            oDataAdapter = New SqlDataAdapter
>            oCommand = New SqlCommand
>            oCommand.Connection = oApp.aConnection(nConnectionString, 2)
>
>
>...where oApp.aConnection is the connection which is already opened at the framework level serving all SQL Server requests from the application.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform