ADO question



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

.



Relevant Pages

  • Re: Clearing out connections in a connection pool ?!
    ... >>> Administrator does NOT clear the existing connections immediately ... >> What Data Access Library are you using DAO or ADO? ... If you are using ADO 2.7 and the ODBC driver. ... You can also use the registry, however, you can't ...
    (microsoft.public.vb.general.discussion)
  • Re: VS 2003.net
    ... retry some connections and then try the create function again. ... myRS is an ado recordset connecting to an ODBC database and a single table. ... IsDBNull does not return the correct value causing runtime errors. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: ADO - Bad when it is time to Optimize
    ... in COM-ATL and the data access is thru ADO to SQL. ... You cannot set the max pool size. ... There is no way to disable the pooling ... You cannot know whether non-pooled connections are happening ...
    (microsoft.public.data.ado)
  • app roles and ADO connections
    ... I'm having problems with the combination of SQL Server ... application roles and ADO connections. ... problematic since the approles is strictly a SQL Server ... In some cases ADO will create additional connections ...
    (microsoft.public.sqlserver.security)
  • Re: MS Access 97 vs. XP/2003
    ... > be a web-based app). ... All the connections to the SQL DB are via ADO. ... recordset, containing modified data, may or may not come back eventually. ...
    (microsoft.public.access.modulesdaovba)

Loading