<%@ language="javascript" codepage="1252" %> <% // ---------------------------------------------------------------------------- // -- $Id: myodbc_catastrophic_failure2.asp 5231 2005-06-27 09:41:51Z wpc0756\Emmanuel $ // ---------------------------------------------------------------------------- %> <% var strDatabase = "testmyodbc"; var strBaseConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Option=2;User ID=testmyodbc;Password=testmyodbc;"; var strConnectionString = strBaseConnectionString + "Database=" + strDatabase + ";"; adStateClosed = 0x00000000; // Indicates that the object is closed. function SQLGetConnection(strRequestedDatabase) { var objConnection = Session("MYSQL_CONNECTION"); if (objConnection != null) { if (objConnection.State == adStateClosed) { // Recreate connection - previous one is closed objConnection = Server.CreateObject("ADODB.Connection"); objConnection.Open(strBaseConnectionString + "Database=" + strDatabase + ";"); } else { SQLUseDatabaseIfDifferent(objConnection, strRequestedDatabase); } } return(objConnection); } function SQLUseDatabaseIfDifferent(objConnection, strRequestedDatabase) { var strCurrentDatabase = null; if (strRequestedDatabase != null) { try { strCurrentDatabase = new String(objConnection.DefaultDatabase); } catch (objException) { } if (strCurrentDatabase != strRequestedDatabase.valueOf()) { SQLExecuteReconnect(objConnection, "USE " + strRequestedDatabase); } } } function SQLExecuteReconnect(objConnection, strSQLOneRequest) { var objResult = null; // Try to reconnect on errors: // CR_SERVER_LOST = 2013 = "Lost connection to MySQL server during query" // CR_SERVER_GONE_ERROR = 2006 = "MySQL server has gone away" try { objResult = objConnection.Execute(strSQLOneRequest); // ERROR: "An exception occurred" (?!?) } catch (objException) { var strMessage = objException.message; if (strMessage.indexOf("Lost connection to MySQL server during query") != -1 || strMessage.indexOf("MySQL server has gone away") != -1) { // Use auto-reconnect: simply redo the same request and MyODBC will reconnect objResult = objConnection.Execute(strSQLOneRequest); } else { throw objException; } } return(objResult); } %>

Start test...

<% try { // Get a connection from Session var objConnection = SQLGetConnection("testmyodbc"); %> Connection fetched.
<% var objRecordset = SQLExecuteReconnect(objConnection, "SELECT * FROM testmyodbc.myodbc_catastrophic_failure WHERE code = 'A';"); %> SELECT 'A' Done - objRecordset.EOF = <%=objRecordset.EOF%>

<% // Get a connection from Session var objConnection = SQLGetConnection("testmyodbc"); %> Connection fetched.
<% var objRecordset = SQLExecuteReconnect(objConnection, "SELECT * FROM testmyodbc.myodbc_catastrophic_failure WHERE code = 'B';"); // Accessing to objRecordset will fail - with error "An exception occurred" %> SELECT 'B' Done - objRecordset.EOF = <%=objRecordset.EOF%>

Test completed with no error!

<% } catch (objException) { %>

<%=objException.message%>

Now the entire IIS process is crashed/heap corrupted - you can't access it anymore...

Try reload, back + reload... heap is corrupted...

<% } %>