CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ADO

  1. #1
    Join Date
    Aug 1999
    Posts
    45

    ADO

    How come I couldn't open it the second time?
    THese are my code:

    'I open the connection and myTable fisrt time:
    With DataEnvironment1.cnnVendor
    .ConnectionString = "Persist Security Info=False;User ID=Admin;" & _
    "Data Source=" & MyDatabaseName & ";"
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Mode = adModeReadWrite
    .Open
    End With
    DataEnvironment1.rsMyTable.Open
    end with

    'I close my connection and myTable:
    DataEnvironment1.rsMyTable.close
    DataEnvironment1.cnnVendor.close

    'I open the connection and myTable second time (exactly the same code!!!)
    With DataEnvironment1.cnnVendor
    .ConnectionString = "Persist Security Info=False;User ID=Admin;" & _
    "Data Source=" & MyDatabaseName & ";"
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Mode = adModeReadWrite
    .Open
    End With
    DataEnvironment1.rsMyTable.Open
    end with

    ---> but the last line "DataEnvironment1.rsMyTable.Open" bomb ???
    The error say :"operation on an object with a reference to a closed or invalid Connection object."

    Please help me out.
    Thanks




  2. #2
    Join Date
    Jan 2000
    Location
    Kansas City, MO
    Posts
    34

    Re: ADO

    Kathy,
    Are you looping through tables, or is this the exact same table object? If your looping through tables you might need to set the table object = Nothing after closing it, and then Set it again at the top of the loop.


    Old school... six lines a day and I'm done.

  3. #3
    Join Date
    Aug 1999
    Posts
    45

    Re: ADO

    It's exacly the same table, and even if I set table record set to nothing,
    still I've got the same error


  4. #4
    Guest

    Re: ADO

    I've found code to help when you get the error you mentioned.

    If DataEnvironment1.cnnVendor.State = adStateClosed then
    DataEnvironment1.cnnVendor.Open
    End If

    -- Adding these few lines of code before you get the error should prevent your problem. This has worked for me and hopefully it helps your problem. If not then I'm sorry I don't know what to tell you.





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured