ado connection problem

Discussion in 'C#' started by paulmilner, May 27, 2009.

  1. #1
    Hi
    I have created a connection to a database but I get the following error
    What can be the cause of such an error
    ........................................................................
    ADODB.Recordset error '800a0e7d'

    The connection cannot be used to perform this operation. It is either closed
    or invalid in this context.

    .......................................................................................

    Here is the code


        If Len(ipMemberID)>0 AND IsNumeric(ipMemberID) Then
         sUpdate="SELECT * FROM tblMembers WHERE ID=" & ipMemberID
      Set opConnection=Server.CreateObject("ADODB.Connection")
         Set opRecordset=Server.CreateObject("ADODB.Recordset")
         opRecordset.open sUpdate, opConnection
             If NOT opRecordset.Eof Then
    
    
    
    sUpdate = "UPDATE  ( sql here)
    
    
    opConnection.execute(sUpdate)
    
    'Close the recordset object
           opRecordset.Close
           Set opRecordset=Nothing
    %> 
    Code (markup):
     
    paulmilner, May 27, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Maybe try closing the recordset before executing the update query. Another thing is, I don't see any End If's to close the blocks.
     
    camjohnson95, May 28, 2009 IP
  3. dopanel.com

    dopanel.com Peon

    Messages:
    93
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    YOu haven't open the database connection
    Adding these codes before opRecordset.open sUpdate, opConnection Command
    
      Dim ConnStr
      ConnStr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source = "& Server.mappath(Databasefile path here) 'If you are using Access Database.
      opConnection.Open ConnStr
    
    Code (markup):
     
    dopanel.com, Jun 1, 2009 IP
  4. zain654321

    zain654321 Peon

    Messages:
    202
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The reason you are getting this error message is because you are summoning the .open() function before your actually creating the object. This is very confusing to the engine!

    Even if you do swap the lines around, it will still not work! This is because you have mixed your objects up. The RecordSet object is used to manage the records returned from an SQL query. You are trying to use it to open a connection to a database.

    You need to use the Connection object rather than the RecordSet object.


    Regards.
     
    zain654321, Jul 8, 2009 IP