I have a program that access MySQL.
I use the following method to connect to MySQL.
Code:
void ConnectDB()
{
HENV hEnv = NULL;
HDBC hDBC = NULL;
RETCODE retcode;
char* szUserName = (char*) sLogin.c_str();
char* szPassword = (char*) strdbPassword.c_str();
char* szDNS = (char*) sDSN.c_str();
SQLAllocEnv(&hEnv);
SQLAllocConnect (hEnv, &hDBC);
retcode = SQLConnect (hDBC, (UCHAR*)szDNS, SQL_NTS, (UCHAR*) szUserName, SQL_NTS, (UCHAR*)szPassword, SQL_NTS);
if (retcode1 == SQL_SUCCESS || retcode1 == SQL_SUCCESS_WITH_INFO)
{
printf("Database connect sucessfully.\n");
}
else
{
printf("Database connect fail.\n");
}
SQLDisconnect( hDBC );
SQLFreeConnect( hDBC );
SQLFreeEnv( hEnv );
}
int main()
{
while( 1 )
{
ConnectDB();
Sleep(1000);
}
return 0;
}
When I run this program, I monitor the memory usage through Task Manager,
I found that the memory usage will increase.
I have done some reserch about the ODBC connection method, some claim that this method will cause memory leak some how.
Can anyone help me on this?