ADO Connection
-
Hello, I am trying to establish a connection and I think I am missing something very basic. I get an "Invalid Pointer" error when the Open() is called. I am importing msado15.dll in StdAfx.h which is included in the file that contains the code below. My code: _ConnectionPtr pConn; HRESULT hr; try{ hr = pConn.CreateInstance(__uuidof(Connection)); _bstr_t bstrDSN = "DSN=test_db;UID=gstewart;PWD=gstewart"; pConn->Open(bstrDSN,"","", -1); } catch (_com_error e){ MessageBox(e.ErrorMessage()); }
-
Hello, I am trying to establish a connection and I think I am missing something very basic. I get an "Invalid Pointer" error when the Open() is called. I am importing msado15.dll in StdAfx.h which is included in the file that contains the code below. My code: _ConnectionPtr pConn; HRESULT hr; try{ hr = pConn.CreateInstance(__uuidof(Connection)); _bstr_t bstrDSN = "DSN=test_db;UID=gstewart;PWD=gstewart"; pConn->Open(bstrDSN,"","", -1); } catch (_com_error e){ MessageBox(e.ErrorMessage()); }
-
The catch block shouldn't be executing in the first place. For some reason my connection pointer isn't valid after hr = pConn.CreateInstance(__uuidof(Connection)); is executed. Any ideas what I'm missing? I think I'm missing a header file or something. It comiles just fine though....????
-
Hello, I am trying to establish a connection and I think I am missing something very basic. I get an "Invalid Pointer" error when the Open() is called. I am importing msado15.dll in StdAfx.h which is included in the file that contains the code below. My code: _ConnectionPtr pConn; HRESULT hr; try{ hr = pConn.CreateInstance(__uuidof(Connection)); _bstr_t bstrDSN = "DSN=test_db;UID=gstewart;PWD=gstewart"; pConn->Open(bstrDSN,"","", -1); } catch (_com_error e){ MessageBox(e.ErrorMessage()); }
This is the code I use to create an ADO connection, the only difference I can see is that I pass cast my empty strings to _bstr_t first. Are you getting a compile error or a runtime error
_ConnectionPtr m_pConnection
HRESULT CAdoConnection::Connect(std::string sConnectionStr)
{
HRESULT hr = S_OK;
try
{
hr = m_pConnection.CreateInstance(__uuidof(Connection));
if(hr == S_OK)
{
hr = m_pConnection->Open(_bstr_t(sConnectionStr.data()), _bstr_t(""), _bstr_t(""), adConnectUnspecified);
}
}
catch (_com_error &e)
{
}return hr;
}
Michael :-)
-
This is the code I use to create an ADO connection, the only difference I can see is that I pass cast my empty strings to _bstr_t first. Are you getting a compile error or a runtime error
_ConnectionPtr m_pConnection
HRESULT CAdoConnection::Connect(std::string sConnectionStr)
{
HRESULT hr = S_OK;
try
{
hr = m_pConnection.CreateInstance(__uuidof(Connection));
if(hr == S_OK)
{
hr = m_pConnection->Open(_bstr_t(sConnectionStr.data()), _bstr_t(""), _bstr_t(""), adConnectUnspecified);
}
}
catch (_com_error &e)
{
}return hr;
}
Michael :-)
-
Michael, I tried the casting and also added the adConnectUnspecified argument. My error occurs at runtime on the Open(...). Thanks, Glen
What error number does the try and catch get for the open? Michael :-)
-
What error number does the try and catch get for the open? Michael :-)
After hr = pConn.CreateInstance(__uuidof(Connection)); the value of hr is -2147221008. I can't seem to get anything more from the _com_error object that is thrown except that the errormessage says "Invalid Pointer". I wonder if there could be something wrong with my compile options? :confused:
-
After hr = pConn.CreateInstance(__uuidof(Connection)); the value of hr is -2147221008. I can't seem to get anything more from the _com_error object that is thrown except that the errormessage says "Invalid Pointer". I wonder if there could be something wrong with my compile options? :confused:
Did you use the CoInitialize()? Cheers!!! Carlos Antollini.