We help IT Professionals succeed at work.

VB6 application can't connect to SQL server except in IDE

Alan_Lau used Ask the Experts™
If I run the following code in the VB6 IDE, it works as I would expect it to:

    connStr = "ODBC;DSN=thales;DATABASE=thales;UID=alanl;PWD=xxxx;"
    MsgBox "Pre-Open database"
    Set db = OpenDatabase("", False, False, connStr)
    MsgBox "Post-Open database"    '  <-- never makes it here

but if I compile it to an .EXE and try to run it, it never makes it to the second msgbox, instead I get an error after about 60 seconds (see attached image)

This is code that has worked for ages, but now all of a sudden isn't.  As far as I know, there haven't been any updates installed on the server, which is running SQL 2005.  Testing the ODBC datasource tests OK.

Any ideas? Connection Error Message
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Check the firewall settings. It can be defined to allow VB6 to communicate the SQL Server (it is the case when you are running your code from IDE), but not to allow your compiled EXE to connect it.


No firewall software is installed.  These are networked PC's behind a Cisco hardware firewall.
Well. I still believe it is somehow related to network/SQL Server/Whatsoever access privileges that are granted to your VB6.exe, but not to your compiled EXE. I had similar issues in the past - and it was default Windows XP firewall (accessible from Control Panel) on the client side, which gave such an effect in my case.
Well, you could try running SQL Profiler to see the connection being established when running in the IDE, and then again in the EXE, just for comparison.  You should at least see the connection being established in both cases.  If not in the EXE case, then I agree with Toyvo that it is something else, may or may not be the firewall though.

What OS are you running on?

Have you tested your EXE on more than one computer?

Try this article (http://support.microsoft.com/kb/195566) to try to check your SQL client install/configuration.

Try this article (http://support.microsoft.com/kb/138541) to test your ODBC connection independantly from the app.


It seems to work on other people's PC's, just not mine.  I tried it on an XP and Windows 7 machine, and both worked.  My PC is Windows 7.  The only thing that I can think of that's significantly different about my PC other than having development tools installed is that I have VMWare and Virtual PC installed.

I'll take a look at the links/suggestions you guys posted.  Thanks.


After walking away from this problem for a couple of days, some combination of installing Windows Updates and/or rebooting my PC seems to have made this problem go away.

Thanks for the help, though.

Glad it's working again.  Those are the troubling solutions because you don't know if/when it will happen again.  Hopefully not!