Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataReader is already opened
Message
De
16/08/2010 12:05:29
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01476630
Message ID:
01476638
Vues:
42
>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.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform