Link to home
Start Free TrialLog in
Avatar of Liu
Liu

asked on

ODBC Error

I am using MFC's CDatabase and CRecordset classes to access a .mdb file from my program.  Sometimes it throw a CDBException with the following error message:

"Disk or network error.
Driver's SQLSetConnectAttr failed"

This error happens when an Open call is made in the CDatabase object.  Usually this error won't go away until I reboot the machine.  

The .mdb file is on the local machine so it doesn't seem to be a network failure.  I can access the .mdb file from other programs while the error is occurring, which means there is probably no disk failure either.  

The program in question sometimes can run for a whole day doing a lot of database operations without having this error.  The same program was running on many other machines with no problem at all.

Any help is appreciated.
Avatar of PMazur
PMazur

>>This error happens when an Open call is made in the CDatabase object.  

Does it mean that the problem happens when you start your application and open the database for the first time? Or do you close and open the database many times from your application?
Avatar of Liu

ASKER

I think it happens when the database is first opened.  My log file shows that the parameter I passed to the Open call is correct and it have worked many times.  It only happens occasionally, but when it happens, I have to reboot the machine to make the error go away.  The strange thing is, I can acccess the .mdb from another program with identical code (without rebooting).
Dear Liu

I think there is a problem with ur ODBC connection.Just check the ODBC and check if the DSN points to the correct
path to ur .mdb file.

Also there is an option in ODBC to repair
the database thats the mdb file.Try that too

Make sure u use the same DSN name in ur program without any mistakes like upper and lower case characters.

After all these delete ur debug folder and make the program to rebuild all.
This should help
I can add that you update your ODBC drivers to the latest available.

Try Service Pack 4 of Visual Studio from Microsoft Download Center.

Good Luck,

Tarik
Avatar of Liu

ASKER

mahsun99,

I have chekced everything mentioned in your reply prior to posting this problem.  

The .mdb file is not damaged in anyway because a reboot of the machine will make the error go away.  Also other programs including MS Access can use the .mdb file without rebooting while this error is happening for one particular program.

The hard to figure out thing is, the program in question could run for a whole day doing the same operations (open, select, insert, delete, etc.) without having this problem.

Avatar of Liu

ASKER

The same version of ODBC driver is used on the machine that is having the problem and on other machines which never have the problem.

Since this is a "production" machine, I cannot update its ODBC driver without convincing certain administrators.

what does it say

page fault?
Stack over flow?
?

Use trace to log the events.

What happens if you handle the exception and on the exception handler handler just make it call the open statement again.

One more question..
Doy you create the database connection once or many times?
Avatar of Liu

ASKER

No page fault or stack over flow.  The exact error message from the CDBException is listed in my original post.  Here is it again:

"Disk or network error.
Driver's SQLSetConnectAttr failed"

It doesn't matter how many times I call the Open method of the CDatabase object.  Once the error occurs, it will have the same error for the same program until I reboot the machine.  But I can open and use the database from a different program with identical DB related code.  

More specifically, my DB code is wrapped in an ActiveX control, the program having the error and other "good" programs are using the same ActiveX control.
Could you post the source code you use to open the connection?
Avatar of Liu

ASKER

Sure.  Here is the source code to open the database.  The FIRST "catch" block is where the CDBException is caught.

/************ code segment ***********/

CString strError;
try
{
  m_db.OpenEx
  (
    strOpen, // open string
    CDatabase::noOdbcDialog
  );
}
catch(CDBException* e)
{
  strError.Format
  (
    _T("Failed to open database '%s': %s\n"),
    strOpen,
    e->m_strError
  );
  // code to write the error to a log file
}
catch(...)
{
  strError = _T("Unexpected exception");
  // code to write the error to a log file
}

/*********** end code segment ********/
What does strOpen contain in the call to OpenEx?
Avatar of Liu

ASKER

It contains the following:

DSN=...;UID=...;PWD=...

I don't think this is a problem because this string never changes and the program can work for many hours before the problem occur.
After your program crashes, before restarting your computer see how much disc space is available in your hard disk.

Some swap file  .tmp are created  in the temp directory and they cannot complete the process because of insufficient space.
When your restart these temp files are deleted.

Make more hard disk space available for the program ( say 100 MB more) and again see how long it runs.

I have no clue what makes the problem.
Try to reproduce the error. And then go to ODBC applet in Control Panel and enable ODBC tracing.

Hopefully it will give more information about the reason for this error.
I bet the other machines which you have no problem with have sufficient hard disk space for the swap files.
Avatar of Liu

ASKER

Space or memory is never a problem.  More then 2 gb of free disk space and more than 300mb of free ram are available all the time.  
As PMazur said try tracing.
Avatar of Liu

ASKER

As I said, the problem only occurs occasionally.  But when it occurs, it gets so bad that we have to reboot the machine.  

We cannot turn the ODBC tracing on and wait for the error to occur, that could take days and it would slow down our apps considerably, the production support people will screaming at us.  Since the error message says it is "Network or disk error", ODBC tracing probably won't give me any more detail.  

And I can't reproduce it on any other machine.  Maybe I should convince my manager to reconfigure (reformat) the machine that is having the problem.
Well, All i can sugest you is to study the enviroment difference between the working and non working machines
Avatar of DanRollins
According to Q197459, some similar errors are informational only.

In your code, have you tried accessing the database after the failure?  -- At least do an IsOpen()?  Have you tried retrying the Open?

Which DBMS are you using?  And can you specify to select a different form of connection (eg, named pipes rather than TCP/IP)?

>>It doesn't matter how many times I call the Open method of the CDatabase object

Yes it does (or at least it could), if the connection is not getting closed correctly between times.  You can use your DBMS tools (Enterprise Manager?) to see if the connection count continues to grow over the life of the program.

I'll keep looking...

-- Dan
Dear LIu

The problem as i said is only due to an
ODBC call failure.
The reason could range from the ms-access version u r using and the ODBC
drivers access being used.

Thats y i am trying to tell u that try repairing the database explicitly.

Also try repairing it in MS-Access itself
u have the option of repairing the database.

Are better still try all the versions of .mdb file.
try to save it as an office95 .mdb,Office97 .mdb and office 2000 .mdb.This will tell u if the problem lies with the drivers.
But i reckon that if u r using Access97 or higher definitely u need an update on ODBC drivers as already pointed out by some one here.

Hope this thing works
Avatar of Liu

ASKER

I already tried repair the database, close the connection and reconnect, etc.

I have learned that there are some differences between the machine that is having the problem and all the other machines (the machine with the problem has ie5 instead of ie4, for example).  There may be other differences I am not aware of.

Anyway, my boss has decided to reconfigure (reformat) the machine sometime soon.  I will let you know if we eventually solve the problem.  Thank you for all the help.  I wish there is a way to divide the 200 pts and give them to you.

Dear Liu
Thanks for ur wish to give the points.Iam not here to add points but to learn more by helping or getting help from others.
To my best of my knowledge here is the last option update the system with MDAC 2.4 orhigher.This should solve ur problem.

Regards
Take Care
This question is still open today, is more needed or have you been helped and can close this?

Thanks,
Asta
Unless there is objection or further activity,  I will suggest to

     "PAQ at zero points"

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
ASKER CERTIFIED SOLUTION
Avatar of Mindphaser
Mindphaser

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial