CCommand Open Failed(oledb) 
Author Message
 CCommand Open Failed(oledb)

Please Correct my code.
m_data.open() Failed

but, I can't find bug.
"SELECT booktitle FROM book" SQL statement is correct.
and "booktitle"  ColumnName and
"book" TableName is exist in access

// code///
void CEeDlg::Func()
{
 CDataSource m_Connect;
 CSession    m_Session;
 CDBPropSet propset(DBPROPSET_DBINIT);

 CCommand<CManualAccessor> m_data;

 try
 {
  USES_CONVERSION;
  CString strTableName("");

  HRESULT hr = S_OK;

  CString strProvider = "Provider=MSDASQL;Data Source=ServerTest";

  // DataSource ???
  hr = m_Connect.OpenFromInitializationString(strProvider.AllocSysString());
  if(FAILED(hr))
  {
   AfxMessageBox(_T("Unable to connect to data source"));
   return ;
  }

  // Session ???
  if (m_Session.m_spOpenRowset != NULL)
   m_Session.m_spOpenRowset.Release();

  hr = m_Session.Open(m_Connect);
  if(FAILED(hr))
  {
   AfxMessageBox(_T("Couldn't create session on data source"));
   return ;
  }

  CComVariant var;
  m_Connect.GetProperty(DBPROPSET_DATASOURCEINFO, DBPROP_DATASOURCENAME,
&var);
  m_strDSN = OLE2T(var.bstrVal);

  CString strSQL;
  strSQL.Format("SELECT booktitle FROM book");

  hr = m_data.Open(m_Session, (LPCSTR)strSQL);   // <== Error Occurred !!!
  if(FAILED(hr))
  {
   m_Connect.Close();
   m_Session.Close();
   AfxMessageBox("DB Open ???D");
   return ;
  }

  while(m_data.MoveNext() == S_OK)
  {
     ///....
  }

  m_data.Close();
  m_Session.Close();
  m_Connect.Close();
 }
 catch(...)
 {
 }

Quote:
}



Mon, 27 Oct 2003 14:52:02 GMT  
 CCommand Open Failed(oledb)
What is the error HRESULT?


Mon, 27 Oct 2003 20:57:08 GMT  
 CCommand Open Failed(oledb)


Quote:
> Please Correct my code.
> m_data.open() Failed

> but, I can't find bug.
> "SELECT booktitle FROM book" SQL statement is correct.
> and "booktitle"  ColumnName and
> "book" TableName is exist in access

> // code///
> void CEeDlg::Func()
> {
>  CDataSource m_Connect;
>  CSession    m_Session;
>  CDBPropSet propset(DBPROPSET_DBINIT);

>  CCommand<CManualAccessor> m_data;

>  try
>  {
>   USES_CONVERSION;
>   CString strTableName("");

>   HRESULT hr = S_OK;

>   CString strProvider = "Provider=MSDASQL;Data Source=ServerTest";

>   // DataSource ???
>   hr =

m_Connect.OpenFromInitializationString(strProvider.AllocSysString());

- Show quoted text -

Quote:
>   if(FAILED(hr))
>   {
>    AfxMessageBox(_T("Unable to connect to data source"));
>    return ;
>   }

>   // Session ???
>   if (m_Session.m_spOpenRowset != NULL)
>    m_Session.m_spOpenRowset.Release();

>   hr = m_Session.Open(m_Connect);
>   if(FAILED(hr))
>   {
>    AfxMessageBox(_T("Couldn't create session on data source"));
>    return ;
>   }

>   CComVariant var;
>   m_Connect.GetProperty(DBPROPSET_DATASOURCEINFO, DBPROP_DATASOURCENAME,
> &var);
>   m_strDSN = OLE2T(var.bstrVal);

>   CString strSQL;
>   strSQL.Format("SELECT booktitle FROM book");

>   hr = m_data.Open(m_Session, (LPCSTR)strSQL);   // <== Error Occurred !!!
>   if(FAILED(hr))
>   {
>    m_Connect.Close();
>    m_Session.Close();
>    AfxMessageBox("DB Open ???D");
>    return ;
>   }

>   while(m_data.MoveNext() == S_OK)
>   {
>      ///....
>   }

>   m_data.Close();
>   m_Session.Close();
>   m_Connect.Close();
>  }
>  catch(...)
>  {
>  }
> }



Tue, 28 Oct 2003 07:26:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. OLEDB (CCommand) Problem

2. CDynamicAccessor - CCommand fails

3. CCommand 's Open method

4. CCommand.Open

5. CCommand.Open

6. SqlConnection - Open - Close - Open - fails

7. CDAODatabase::Open fails when trying to open 2nd mdb

8. OLEDB rowset object MoveFirst fails for varchar 2000

9. OLEDB, Fail Insert, SQL Server 7

10. OLEDB provider fails when using AppWizard

11. Open a database with OLEDB in a ATL service EXE file

12. Can't open OLEDB Recordset under DB2?

 

 
Powered by phpBB® Forum Software