Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Enumerator behavior
Message
De
29/03/2007 13:56:02
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Titre:
Enumerator behavior
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01209957
Message ID:
01209957
Vues:
43
I have been having a problem that occurs occasionnaly since a few months. It is extremely difficult to troubleshoot. It is about the Enumerator way of doing things. I have this method:
        Private Function InitializeDataObject(ByVal tcSql As String) As Boolean
            Dim loEnumerator As IEnumerator = oParameters.GetEnumerator
            Dim loParameter As Object
            cSQL = tcSql
            oParameters2.Clear()

            nBackend = oApp.aConnection(nConnectionString, 4)
            nSQLMode = oApp.aConnection(nConnectionString, 3)

            ' Different backends handle it differently
            Select Case nSQLMode

                ' OleDb
                Case 1
                    oDataAdapter = New OleDbDataAdapter
                    oCommand = New OleDbCommand
                    While loEnumerator.MoveNext
                        loParameter = loEnumerator.Current
                        oDataParameter = New OleDbParameter("@" + loParameter(1, 1).ToString, loParameter(1, 2))
                        oParameters2.Add(oDataParameter)
                    End While

                    ' SQLClient
                Case 2
                    oDataAdapter = New SqlDataAdapter
                    oCommand = New SqlCommand
                    While loEnumerator.MoveNext
                        loParameter = loEnumerator.Current
                        oDataParameter = New SqlParameter("@" + loParameter(1, 1).ToString, loParameter(1, 2))
                        oParameters2.Add(oDataParameter)
                    End While

                    ' ODBC
                Case 3
                    oDataAdapter = New OdbcDataAdapter
                    oCommand = New OdbcCommand
                    While loEnumerator.MoveNext
                        loParameter = loEnumerator.Current
                        oDataParameter = New OdbcParameter("@" + loParameter(1, 1).ToString, loParameter(1, 2))
                        oParameters2.Add(oDataParameter)
                    End While
            End Select
            oParameters.Clear()

            Try
                oCommand.Connection = oApp.aConnection(nConnectionString, 2)
            Catch loError As Exception
                DataError(loError, oApp.Debug(cSQL + ErrorDetail()))
            End Try

            Return True
        End Function
As you can see, the first declaration gets a handle on the oParameters object. Once this method is about to be completed, I also issue oParameters.Clear() to clear the container.

However, even if I clear the container on execution of that method, I believe a loEnumerator.Reset() should be required right after the declaration as when I make several calls to this method, from the same object, this sometimes gives me an "Object reference not set to an instance of an object." message later down the code when I deal with the oParameters2 object. I always assume that because the oParameters is cleared that I wouldn't need the loEnumerator.Reset() command. Is that really the case? Anyone would like to comment on that?
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
Répondre
Fil
Voir

Click here to load this message in the networking platform