Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Already an open DataReader?
Message
De
15/01/2013 15:14:07
 
 
À
15/01/2013 15:00:13
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01562745
Message ID:
01562775
Vues:
29
You can only use 'using' for classes that implement IDisposable



>Thanks Naomi, that took care of that error - now a new one, but it's dealing with the substring, so I need to check that I'm getting what I expect to get.
>
>
>>>I'm getting a 'Already as open DataReader of that name' error on the following code:
>>>
>>>
>>>    Using sconn As New SqlConnection(ConnString)
>>>      Try
>>>        PswrdTries = PswrdTries + 1
>>>        If PswrdTries > 2 Then
>>>          Me.Close()
>>>        End If
>>>        sconn.Open()
>>>        Dim msql1 As String = "Select * from CATDecode where DecName = 'PASSWORD'"
>>>        Using ms1 As New SqlCommand(msql1, sconn)
>>>          Using ds1 = ms1.ExecuteReader
>>>            If ds1.Read Then
>>>              If Trim(ds1.Item("DecValue").ToString.ToUpper) <> Trim(txtPassWord.Text.ToUpper) Then
>>>                MsgBox("Password does not match" & vbCrLf & "One try left", vbOKOnly + vbCritical, "Incorrect Password")
>>>              Else
>>>                Dim msql2 As String = "Select * from CATDecode where DecName = 'SUBBANK'"
>>>                Using ms2 As New SqlCommand(msql2, sconn)
>>>** Error occurs on next statement **
>>>                  Using ds2 = ms2.ExecuteReader
>>>                    If ds2.Read() Then
>>>                      TestSub = ds2.Item("DecValue").ToString.Substring(4, ds2.Item("DecValue").ToString.Length)
>>>                    End If
>>>                  End Using
>>>                End Using
>>>              End If
>>>            End If
>>>          End Using
>>>        End Using
>>>        sconn.Close()
>>>      Catch ex As Exception
>>>        sconn.Close()
>>>        MsgBox("Sql Exception:  " & ex.Message)
>>>      End Try
>>>    End Using
>>>
>>>
>>>What am I missing?
>>
>>I think you have too many using statements. After you opened the connection, don't do any more using, just define a variable for data reader and read the results, then close the reader. Then do another one as a normal variable also.
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform