I have a c++ application that connects to SQL Server 2005 using OLE DB / Native client. If the connection gets broken or for example the session is killed from the database something causes the connection to do an automatic reconnect. The problem is that in that case for example all temporary tables created previous connection are lost.
Is there any way to prevent this from happening, or somehow notice that this has happened? That way I could do the same steps as in the original connection.
I tried to add "ConnectRetryCount=0" and "Connect Retry Count=0" to connect string, which I found from here: https://msdn.microsoft.com/en-us/library/jj730312%28v=sql.110%29.aspx but that made no difference, even when I tested the same application native client 11 and SQL Server 2014.
Best Answer
You can check if the temporary object exists using this:
Another thing you could do is check the connection time for the current connection:
However, I'm having a hard time believing that the client disconnects without throwing errors. I would try to catch those errors first.