Home Forums Programming Connecting Error 3709 The connection cannot be used to perform this operation. It is either closed or invalid in this contex RE: Error 3709 The connection cannot be used to perform this operation. It is either closed or invalid in this contex

  • I typically see this when an ADODB connection has not been opened, and then you try to open a recordset with the still closed connection;

    for example:

    dim conn As New ADODB.Connection

    conn .ConnectionString = Provider=SQLOLEDB;Persist Security Info=False;User ID=sa;Password=unknown;Initial Catalog=pubs;Network Library=dbmssocn; Data Source=someserver;   

    conn .CursorLocation = adUseClient

    '--commented out to duplicate error!

    'conn.Open

     dim rs as new adodb.recordset

    rs.Open "SELECT * FROM AUTHORS", conn, adOpenStatic, adLockReadOnly

     

    --THIS WILL RAISE THE ERROR BECAUSE THE CONNECTION IS NOT OPEN

    In an app I had, the connection was opened in a separate procedure with on error resume next, and then a different procedure, which assumed the conn was .Open would raise the same error, because the previous connection failed error was supressed.

     

    hope that helps

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!