ADO question
- From: "Benry" <henrybg@xxxxxxxxx>
- Date: 2 Feb 2006 11:19:18 -0800
I've been using ODBC for all of my DB connections, but found a solution
for a problem I was having using ADO. I've been reading mdsn all day
searching for something that is coherent regarding ADO. I want to post
my code, and tell you where I'm having problems. Most of this is
borrowed and not yet cleaned up. I'm trying to execute a stored
command (SQL Server) by issuing a raw SQL command in the form of
"strSQLDBFetch". When I issue this command in an SQL command line, I
get all of the databases on the server I'm connected to.
My problem is after the connection, in the line that says "pRstTitles =
pCmdChange->Execute(NULL,NULL,NULL);" I've set the command text for
pCmdChange, but can't get the SQL to return a recordset.
1.) Am I thinking about this incorrectly?
2.) Should I figure something out so I can use ODBC where I'm more
comfortable?
3.) Where is there good documentation on ADO?!
_bstr_t strSQLDBFetch("EXEC sp_databases");
ADONS::_ConnectionPtr spConnection = NULL;
ADONS::_CommandPtr pCmdChange = NULL;
ADONS::_RecordsetPtr pRstTitles = NULL;
HRESULT hr2 =
spConnection.CreateInstance(__uuidof(ADONS::Connection));
if (FAILED(hr2))
_com_issue_error(hr2);
if (SUCCEEDED(hr2))
{
if (m_bUseNTAuthentication){
m_ctlComboBox.GetWindowText(sTemp);
sConnectionString.Format(_T("provider=SQLOLEDB;server=%s;Trusted_Connection=yes;database=master"),
sTemp);
}
else{
m_ctlComboBox.GetWindowText(sTemp);
m_ctlEditName. GetWindowText(sTemp1);
m_ctlEditPassword.GetWindowText(sTemp2);
sConnectionString.Format(_T("provider=SQLOLEDB;server=%s;uid=%s;pwd=%s;database=master"),
sTemp, sTemp1, sTemp2);
}
spConnection->ConnectionString = _bstr_t(sConnectionString);
spConnection->ConnectionTimeout = 30;
hr2 = spConnection->Open (_bstr_t(sConnectionString), "", "",
ADONS::adConnectUnspecified);
if (FAILED(hr2))
{
_com_issue_error(hr2);
}
else{
HRESULT hr4 = pCmdChange.CreateInstance(__uuidof(ADONS::Command));
if(FAILED(hr4))
_com_issue_error(hr4);
if(SUCCEEDED(hr4)){
pCmdChange->ActiveConnection = spConnection;
pCmdChange->CommandText = strSQLDBFetch;
pRstTitles.CreateInstance(__uuidof(ADONS::Recordset));
pRstTitles = pCmdChange->Execute(NULL,NULL,NULL);
m_ctlComboDB.ResetContent();
LRESULT hr3 = pRstTitles->MoveFirst();
while(hr3){
sTemp = (LPCSTR)pRstTitles->GetDataMember();
m_ctlComboDB.AddString(sTemp);
hr3 = pRstTitles->MoveNext();
}
}
}
}
Thanks,
Ben
.
- Follow-Ups:
- Re: ADO question
- From: Benry
- Re: ADO question
- Prev by Date: Re: Creating CDialog in DLL?
- Next by Date: Re: Corrupt TCP segments using CSocket
- Previous by thread: Re: Disabling NIC
- Next by thread: Re: ADO question
- Index(es):
Relevant Pages
|
Loading