This is a discussion on ODBC api throws exception 0xC0000005 when freeing handles in the wrong order within the MS SQL ODBC forums, part of the Microsoft SQL Server category; --> Hi, i discovered that the ODBC api throw an acces violation exception if i close handles in the wrong ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, i discovered that the ODBC api throw an acces violation exception if i close handles in the wrong order. is this a bug? i thought that the ODBC API was supposed to return INVALID_HANDLE if a supplied handle was not valid anymore? i work with Visulal C++ 7.1, windows XP and SQL server 2000 SP2. i have also tried this with access. int main(void) { HENV henv; HDBC hdbc; HSTMT hstmt; unsigned char sDSN[] = "northwind"; unsigned char sLogin[] = "sa"; unsigned char sPassword[] = ""; SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER); //try to allocate a connectionhandle SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); //try to connect the connectionhandle to a DSN SQLConnect(hdbc, sDSN, strlen((char*)sDSN), sLogin, strlen((char*)sLogin), sPassword, strlen((char*)sPassword)); //try to create a new stmt handle SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); //close the connection handles SQLDisconnect(hdbc); SQLFreeHandle(SQL_HANDLE_DBC, hdbc); SQLFreeHandle(SQL_HANDLE_ENV, henv); //free the statement handle. //now it will crash SQLFreeHandle(SQL_HANDLE_STMT,hstmt); return 0; } is there a way to make the api not throw exceptions? i know that the handles should be closed in a different order, but due to specific reasons i cannot guarantee this. in this case it shoudl return an error. kind regards, Bruno. |
| ||||
| Sorry, the ODBC documentation explicitly states that the behavior is undefined in this case. When you call SQLDisconnect() (and it returns SQL_SUCCESS) it will free your statement handles for you. This is by design. Brannon "Bruno van Dooren" <microvax@hotmail.com> wrote in message news:uKzIBxngDHA.2188@TK2MSFTNGP10.phx.gbl... > Hi, > > i discovered that the ODBC api throw an acces violation exception if i close > handles in the wrong order. > is this a bug? i thought that the ODBC API was supposed to return > INVALID_HANDLE if a supplied handle was not valid anymore? > > i work with Visulal C++ 7.1, windows XP and SQL server 2000 SP2. i have also > tried this with access. > > int main(void) > { > HENV henv; > HDBC hdbc; > HSTMT hstmt; > unsigned char sDSN[] = "northwind"; > unsigned char sLogin[] = "sa"; > unsigned char sPassword[] = ""; > > SQLAllocHandle(SQL_HANDLE_ENV, > SQL_NULL_HANDLE, > &henv); > > SQLSetEnvAttr(henv, > SQL_ATTR_ODBC_VERSION, > (SQLPOINTER) SQL_OV_ODBC3, > SQL_IS_INTEGER); > > //try to allocate a connectionhandle > SQLAllocHandle(SQL_HANDLE_DBC, > henv, > &hdbc); > > //try to connect the connectionhandle to a DSN > SQLConnect(hdbc, > sDSN, > strlen((char*)sDSN), > sLogin, > strlen((char*)sLogin), > sPassword, > strlen((char*)sPassword)); > > //try to create a new stmt handle > SQLAllocHandle(SQL_HANDLE_STMT, > hdbc, > &hstmt); > > //close the connection handles > SQLDisconnect(hdbc); > SQLFreeHandle(SQL_HANDLE_DBC, hdbc); > SQLFreeHandle(SQL_HANDLE_ENV, henv); > > //free the statement handle. > //now it will crash > SQLFreeHandle(SQL_HANDLE_STMT,hstmt); > > > return 0; > } > > is there a way to make the api not throw exceptions? i know that the handles > should be closed in a different order, but due to specific reasons i cannot > guarantee this. in this case it shoudl return an error. > > kind regards, > Bruno. > > |
| Thread Tools | |
| Display Modes | |
|
|