Ado访问oralce导致内存上涨以及句柄数上涨
我写了个用ado访问数据库的类,做测试的时候我不停的读库,关闭库,可是发现内存一直在涨,程序对应的句柄也涨,我该释放的地方也释放了,以下打开库和关闭库的代码,希望有高手能帮我看一下
BOOL CDataBase::OpenMyConnection()
{
HRESULT hr;
m_connect=FALSE;
try
{
hr = m_pConnection.CreateInstance( "ADODB.Connection ");///创建Connection对象 if( SUCCEEDED(hr) )
{//SHOUGBF2//WJTEST
CString strConn;
strConn.Format( "Provider=MSDAORA.1;Password=%s;User ID=%s;Data Source=%s;Persist Security Info=True; ",m_password,m_username,m_servername);
hr = m_pConnection- >Open((_bstr_t)strConn, " ", " ",adConnectUnspecified);//adConnectUnspecified
m_connect=TRUE; } }
catch(_com_error e)///捕捉异常 { CloseMyConnection();
CString temp;
temp.Format( "连接数据库错误信息::%s ",e.ErrorMessage());
//::::MessageBox(NULL,temp, "提示信息 ",NULL);
m_connect=FALSE;
} return m_connect;
} void CDataBase::CloseMyConnection()
{
if(m_pConnection!=NULL)
{
try
{
if(m_pConnection- >State!=adStateClosed)
{
m_pConnection- >Close();
}
m_pConnection.Release();
m_pConnection=NULL;
}
catch(_com_error e)///捕捉异常
{
m_pConnection.Release();
//m_pConnection- >Release();
m_pConnection=NULL; }
}
}
我写了个用ado访问数据库的类,做测试的时候我不停的读库,关闭库,可是发现内存一直在涨,程序对应的句柄也涨,我该释放的地方也释放了,以下打开库和关闭库的代码,希望有高手能帮我看一下
BOOL CDataBase::OpenMyConnection()
{
HRESULT hr;
m_connect=FALSE;
try
{
hr = m_pConnection.CreateInstance( "ADODB.Connection ");///创建Connection对象 if( SUCCEEDED(hr) )
{//SHOUGBF2//WJTEST
CString strConn;
strConn.Format( "Provider=MSDAORA.1;Password=%s;User ID=%s;Data Source=%s;Persist Security Info=True; ",m_password,m_username,m_servername);
hr = m_pConnection- >Open((_bstr_t)strConn, " ", " ",adConnectUnspecified);//adConnectUnspecified
m_connect=TRUE; } }
catch(_com_error e)///捕捉异常 { CloseMyConnection();
CString temp;
temp.Format( "连接数据库错误信息::%s ",e.ErrorMessage());
//::::MessageBox(NULL,temp, "提示信息 ",NULL);
m_connect=FALSE;
} return m_connect;
} void CDataBase::CloseMyConnection()
{
if(m_pConnection!=NULL)
{
try
{
if(m_pConnection- >State!=adStateClosed)
{
m_pConnection- >Close();
}
m_pConnection.Release();
m_pConnection=NULL;
}
catch(_com_error e)///捕捉异常
{
m_pConnection.Release();
//m_pConnection- >Release();
m_pConnection=NULL; }
}
}
1,如果打开了记录集,关闭记录集:
m_pRs->Close();
m_pRs=NULL;
2,关闭连接:
m_pConn->Close();
m_pConn=NULL;