I recently developed a database installation utility that creates an MSSQL database for our application. The application uses ADO to run commands against the SQL server. The database and objects in it are created using SQL queries.
After creating the database the application executes a
Where database name is the name of the database entered into the utility.
The code is MFC based Visual Studio .Net using ADO to connect. All database code is wrapped in try / catch statements.
This seems to work fine except at one site where we are get an "Error" [Error 0 Changed Database Context to 'databasename']. Research seems to indicate this is a purely informational message and can be ignored. However, given the code is in a try / catch block we have the following problem
CString sQuery ;
sQuery.Format ( "CREATE DATABASE [%s] ON NAME .... " ) ;
pConn->Execute ( sQuery.AllocSysString(), NULL, adCmdText ) ; // THIS Works
sQuery.Format ( "USE %s", m_database) ;
pConn->Execute ( sQuery.AllocSysString(), NULL, adCmdText ) ; // Exception is thrown with error = 0 Changed Database Context to '<databasename>'
sQuery.Format ( "Create table x ... " ) ; // Code does not get here
pConn->Execute ( sQuery.AllocSysString(), NULL, adCmdText );
// More create statements
catch ( _com_error & e )
if (!DisplayADOError ( pConn ) )
DisplayCOMError ( e ) ;
Basically the problem at the site in question is that an exception is being thrown when the DB context is changed thereby interrupting execution so the rest of the database create statements are not run.
Any idea why this information message is coming through as an exception ?
How do I stop it ?
Is there an equivalent of resume next that can be used in catch whereby an error can be ignored and code can continue processing ?