ADO Problem with calling a stored procedure in MS Access 2000 
Author Message
 ADO Problem with calling a stored procedure in MS Access 2000

I am using sample Northwind.MDB that came with Office 2000.  The code
snippet below connects and runs successfully if the stored procedure
is one word (such as "Invoices" below).

However, when I try to run another stored procedure that contains more
than one word, such as "Current Product List", an exception is thrown.
I've tried "CurrentProductList" and the same problem.

What _bstr_t do I use to run a stored procedure that is more than one
word?  Thanks for your help.


ErrorMessage:IDispatch error #3092.
Source:Microsoft JET Database Engine.
Description:Invalid SQL statement; expected 'DELETE', 'INSERT',
First-chance exception in ADO.exe (KERNEL32.DLL): 0xE06D7363:
Microsoft C++ Exception.


_CommandPtr pCommand;
pCommand.CreateInstance( __uuidof( Command ) );
CADODoc * pDoc = GetDocument();

        pCommand->ActiveConnection = pDoc->m_pConnection;
        pCommand->CommandType = adCmdStoredProc;            
        pCommand->CommandText = _bstr_t( "Invoices" );    

        _variant_t vNull;
        vNull.vt = VT_ERROR;
        vNull.scode = DISP_E_PARAMNOTFOUND;

_RecordsetPtr pRS = pCommand->Execute( &vNull, &vNull, adCmdUnknown );
        if( !pRS->GetadoEOF() )
                CListCtrlEx& ctlList = (CListCtrlEx&) GetListCtrl();

                ctlList.AddColumn("  ProductID   ",0);
                ctlList.AddColumn("  ProductName ",1);
                ctlList.AddColumn("  Counter     ",2);

                _variant_t vProductID, vProductName;
                int i = 0;

                while( !pRS->GetadoEOF() )
                vProductID = pRS->GetCollect(L"ProductID");
                ctlList.AddItem(i,0,(_bstr_t) vProductID);
                vProductName = pRS->GetCollect(L"ProductName");
                ctlList.AddItem(i,1,(_bstr_t) vProductName);
                m_strConvert.Format("%d", i);        
                ctlList.AddItem(i, 0, (LPCTSTR) m_strConvert);
        TRACE("\nEOF reached.  Closing Database Connection! \n");


catch( _com_error &ex )
        TRACE( "Error:%08lx.\n", ex.Error() );
        TRACE( "ErrorMessage:%s.\n", ex.ErrorMessage() );
        TRACE( "Source:%s.\n", (LPCTSTR) _bstr_t(ex.Source())
TRACE( "Description:%s.\n", (LPCTSTR) _bstr_t(ex.Description()) );

Sat, 06 Sep 2003 17:03:49 GMT  
 ADO Problem with calling a stored procedure in MS Access 2000
_bstr_t is one of the compiler COM support classes declared in COMDEF.H. It
wraps the BSTR type to provide useful operators and methods. See the
"Compiler COM Support Classes" for more information.

Refer to the sample "ActiveConnection, CommandText, CommandTimeout,
CommandType, Size, and Direction Properties Example (VC++)" in MSDN.

In here you can don't use _bstr_t also.

From the code it should be ok. Is the store procedure "Current Product
List"'s syntax right?

Sun, 07 Sep 2003 17:39:45 GMT  
 ADO Problem with calling a stored procedure in MS Access 2000
If there are blanks within the name using the following format to do this.

pCommand->CommandText = "[Current Product List]";

Mon, 08 Sep 2003 09:03:13 GMT  
 [ 3 post ] 

 Relevant Pages 

1. Porting SQL Server 7 Stored Procedures to Access 2000

2. Problems calling Oracle stored procedures from VC++ over ADO(OLEDB)

3. ADO Stored Procedure Calls with C++

4. ADO call stored procedure

5. SqlCommand object and stored procedures in SQL Server 2000

6. access violation exception after stored procedure call

7. Executing stored procedure on sql server 2000 using c program

8. Problem with transfer parameters to a stored procedure using ADO

9. Problem stored procedure with ADO

10. Accessing an Ms Access 2000 Query using VC++, via ODBC

11. Problem with DAO direct calls and Access 2000 databases

12. CTime problem in call stored procedure


Powered by phpBB® Forum Software