#include "StdAfx.h"
//#include "Receive.h"
#include "Connectsql.h"
BOOL ConnectSql::connect(CString connectstr)
{
HRESULT hr;
CoInitialize(NULL);
pConn.CreateInstance(_uuidof(Connection));
pRst.CreateInstance(_uuidof(Recordset));
pCmd.CreateInstance(_uuidof(Command));
pConn->ConnectionString=(_bstr_t)connectstr;
try
{
hr=pConn->Open("","","",adCmdUnspecified);
}
catch (_com_error &e)
{
AfxMessageBox(e.ErrorMessage());
m_bConnected = FALSE;
}
return m_bConnected;
}
void ConnectSql::disConnect()
{
// if(pRst!=NULL)
//// {
// pRst->Close();
// pRst.Release();
//// }
pConn->Close();
// if(pCmd)
// {
// pCmd.Release();
// }
// pCmd.Release();
// pRst.Release();
pConn.Release();
CoUninitialize();
}
- 1
- 2
- 3
前往页