Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7129897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:17:31+00:00 2026-05-28T11:17:31+00:00

I have an old visual basic 6 application when some users reported me errors

  • 0

I have an old visual basic 6 application when some users reported me errors when the computer going back from sleep. This problem did not occurs on every client computer, (I would say some Windows 7). If the vb6 application was still open then if they try to use this application it crashes with the following error message.

enter image description here

I debugged and I found the problem: I have a global variable that keep the connection to the database. This variable is initialized only once in the beginning of the application. When the computer going to sleep and go back some times later, the status of this variable is still “OPEN” but in fact the connection is lost! If I “CLOSE” and then “OPEN” this variable connection I am able to query the database.

I wonder if this is normal that I lost my database connection?!

Here is some code:

 ' This is my global variable
 Global cn As New ADODB.Connection

 ' Set connection properties for sql server.
 cn.ConnectionTimeout = 25
 cn.Provider = "sqloledb"
 cn.Properties("Data Source").Value = ".\SQL2008"
 cn.Properties("Initial Catalog").Value = DB_INITIAL_CATALOG
 cn.Properties("User ID").Value = DB_USERNAME
 cn.Properties("Password").Value = DB_PASSWORD
 cn.Open

 ' This is a typical query on my database
 Set rs = New ADODB.Recordset
 strSql = "SELECT * FROM tblUsers"
 rs.Open strSql, cn, adOpenKeyset

Any idea?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:17:32+00:00Added an answer on May 28, 2026 at 11:17 am

    Yes, I’ve seen this kind of thing before. There may be settings on the connect string that can help reduce it, but time outs and/or network drops can break the underlying (often TCP) connection to the DB server. You then see the error manifest itself in the next I/O to the database.

    I recommend wrapping access to the shared connection so you can transparently catch that specific error and retry. Keep the connection private in a class or module and have methods such as:

    'Open is called to set the args to connect, these should be saved for reconnect
    Public Sub Open(connect params here)
    
        'save arsg to prive members to reconnect
    
        'connect to db
    
    End Sub
    
    Public Function OpenKeyset(sql) As RecordSet
    
       Set rs = New ADODB.Recordset  
    
       On Error Resume Next
       rs.Open strSql, privateConn, adOpenKeyset
    
       'if the error is the disconnect
       If Error.Number = xxx Then 'or inspect the error message or error collection
    
          'turn of error trap
          Err.Clear
          On Error Goto 0
    
          'reopen db conn
    
          'then retry
          rs.Open strSql, privateConn, adOpenKeyset
    
       End If
    
       OpenKeyset = rs
    
    End Function
    

    You could even periodically perform a no-op db operation like quering the catalog or whatever to keep the connection live and proactivle reconnect. You couild also watch for large jumps in time that happen if a computer hibernates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got some old sources written in Visual Basic. There are *.bas ,
I currently rewrite an old Visual Basic application in java, a large part of
In a very old code base, we have some build settings for our visual
I have old code that uses size_t which IIRC comes from cstring.h. On OS
I have an old J2EE application (J2EE 1.3), which packages into an EAR, and
I have an old function that is called many times in my application. I
I have some old branches in my git repository that are no longer under
I'm fairly new to Visual Studio (specifically Visual Basic .NET) but have been programming
I have a old install of visual c++ 6.0. I'd like to bring things
Okay, so I have a legacy Codebase and an old Visual C++ 6.0 Standard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.