La conexión de SQL-Server falla después de la reconexión de la red

I am working on an update to an application that uses DAO to access an SQL Server. I know, but let's consider DAO a requirement for now.

The application runs all the time in the system tray and periodically performs SQL server operations. Since it is running all the time, and users of the application will be on laptops and transitioning between buildings, I've designed it to quietly transition between active and inactive states. When the database connection is successful operations resume.

I have one last issue before I release this update: When a connection is dropped, then reestablished, the SQL operations fail. This occurs only if I have specified the hostname in my connection string. If I use the IP, everything is fine (but I need to be able to use hostname).

Here is the behavior:

1) Everything working. Good network connection, database operations are fine.

2) Lost connection. Little 'x' appears on task bar icon, and nothing else. All ok.

3) Reconnect.

At step 3, I get an 'ODBC--call failed' error when I run the first query. Interestingly, the database is first opened without error.

If I skip step 1, and start the application when the connection is down, everything works fine in step 3, hostname or not.

I expect this is an issue with the DAO engine caching the DNS entry after the first connection, although the destination IP does not change so I'm not sure about that. I have tried flushing the windows DNS cache (from cmd prompt) to no effect. The same behavior occurs even when I'm using my local hostname with a local SQL server I set up for development. has no problems.

I also tried to CoUninitialize() the DAO interface between active times, but I had trouble getting this to work. If someone thinks that would help I will work harder at it.

This behavior is the same in Windows XP or 7.

Thanks for anything you've got!

Edit: I should have mentioned - I am closing the database connection between the attempts, then reopening it with

m_pDb = m_pDaoEngine->OpenDatabase()

preguntado el 09 de marzo de 12 a las 15:03

1 Respuestas

I ended up biting the bullet and converting the application to ADO. Everything works nicely now, and database operations are much faster to boot.

respondido 12 mar '12, 20:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.