VC连接ACCESS数据库的有关问题

VC连接ACCESS数据库的问题
麻烦高手给看下这个函数有什么问题,如果有问题的话给优化下吧,请多多指点……
bool Equipment_1(string equipment)
{
_ConnectionPtr m_connection;//声明Connection指针
  _RecordsetPtr m_recordset;//声明Recordset指针
bool Exist;
string strDatabaseFile="C:\\Program Files\\Harvest\\ARJ21.mdb";
if(m_connection) 
{
// Close the recordset if it's open
if (m_recordset)
{
// Check if the state is open, and if so, close it.
if (m_recordset->State ==adStateOpen)
m_recordset->Close();
}

// If we have a valid connection pointer, close it and unset COM.
if(m_connection)
{
m_connection->Close();
CoUninitialize();
}

// Set our pointer variables to NULL
m_connection = NULL;
m_recordset = NULL;
}
HRESULT hResult;
CoInitialize(NULL);

try
{
hResult = m_connection.CreateInstance(__uuidof(Connection));
if (FAILED(hResult))
{
throw _com_error(hResult);
}

hResult = m_recordset.CreateInstance(__uuidof(Recordset));

// If we weren't able to create a recordset instance, throw an error.
if (FAILED(hResult))
{
throw _com_error(hResult);
}

char szConnection[255] = {0};
sprintf(szConnection, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=%s", strDatabaseFile.c_str());
m_connection->CursorLocation =adUseClient;

// To convert our char string to a bstr we use the _bstr_t() function.
_bstr_t strConnection = _bstr_t(szConnection);

// Finally, open a connection to the database by passing in the connection string,
// userID, password, and options for asynchronous or synchronous connection. We use
// adConnectUnspecified for a synchronous connection, or you can use adAsyncConnect.
// We pass in blank bstr's for the user ID and password since we don't have one.
m_connection->Open(strConnection, _bstr_t (""), _bstr_t (""),adConnectUnspecified);
}

// If we received any errors during our "try" scope, post an error message
catch(_com_error &e)
  {
MessageBox(NULL, static_cast<char *>(e.Description()), "Error", MB_OK);
  }

  catch(...)
  {
MessageBox(NULL, "Unhandled Exception", "Error", MB_OK);
  }
// Since we use the name of the database table a lot, let's store it.
string strTable = "DLLEXPERIMENT";
string strWhere = "Input_Function='" + equipment + "'";

// This next line returns the record count in the desired table. The
// record count refers to the rows in the table.
// Check if our database is connected, otherwise return.
if(m_connection) 
{

  char szSQLStatement[255] = {0};
sprintf(szSQLStatement, "SELECT Input_Function FROM %s WHERE %s", strTable.c_str(), strWhere.c_str());

m_recordset->Open(szSQLStatement, m_connection.GetInterfacePtr(),adOpenForwardOnly, adLockReadOnly,adCmdText);

// Before closing the recordset we need to grab the record count
int rowCount = m_recordset->RecordCount;
  if (m_recordset)
{
// Check if the state is open, and if so, close it.
  if (m_recordset->State ==adStateOpen)
  m_recordset->Close();
}

if(rowCount>0)
Exist=true;
else
Exist=false;
// Return the row count
return Exist;
}
}

------解决方案--------------------
没必要每次调用函数Equipment_1都搞一遍CoInitialize(NULL);
------解决方案--------------------