Problem calling a stored procedure
- From: slaskkonto@xxxxxxxx
- Date: 10 Jul 2006 22:35:25 -0700
Hi!
I have a method which i have used for a long time passing ordinary sql
expressions (SELECT,INSERT, UPDATE and so on) to databases. But now im
forced to call a stored procedure in SQL Server. So i thought i'd use
the same code. But it doesnt work. I always get error -2147217887 when
running ICommandText->Execute. Can anyone please look att the code
snippet below and see if you can figure out what is wrong? Any help is
most appriciated!
ExecuteStoredProcedure(TCHAR *command)
{
//command value is EXEC proc_itemtest 'R' ,0
HRESULT ret_val = 0L;
WCHAR *cmd_str = 0L;
int jj = 0;
int i= 0;
m_ColOffset = 0;
// Obtain a pointer of IDBCreateSession interface
if ( FAILED( m_Interface->QueryInterface( IID_IDBCreateSession,
(void**) &m_IDBCreateSession ) ) )
{
...
}
// Create a session with database
if ( FAILED( m_IDBCreateSession->CreateSession( NULL,
IID_IDBCreateCommand, (IUnknown**) &m_IDBCreateCommand ) ) )
{
...
}
m_IDBCreateSession->Release();
m_IDBCreateSession = 0L;
// Create a command to execute SQL statement
if ( FAILED( m_IDBCreateCommand->CreateCommand( NULL,
IID_ICommandText, (IUnknown **) &m_ICommandText ) ) )
{
....
}
m_IDBCreateCommand->Release();
m_IDBCreateCommand = 0L;
ToUnicode( &cmd_str, command );
// Set command properties
if ( !FAILED( m_ICommandText->QueryInterface(
IID_ICommandProperties,
(void **) &m_ICommandProperties ) ) )
{
CMOOLEDB_PROPSFLAGS
crs_props[CMOOLEDBQUERY_NOFCOMMANDPROPS] = {
// {DBPROP_SERVERCURSOR, true},
// {DBPROP_CLIENTCURSOR, true},
// {DBPROP_DEFERRED, false},
// {DBPROP_IRowsetChange, false},
// {DBPROP_IRowsetLocate, false},
// {DBPROP_IRowsetScroll, false},
// {DBPROP_IRowsetUpdate, false},
// {DBPROP_BOOKMARKS, false},
// {DBPROP_CANFETCHBACKWARDS, false},
// {DBPROP_CANSCROLLBACKWARDS, false},
{DBPROP_CANHOLDROWS, true},
// {DBPROP_LITERALBOOKMARKS, false},
// {DBPROP_OTHERINSERT, true},
// {DBPROP_OTHERUPDATEDELETE, true},
// {DBPROP_OWNINSERT, true},
// {DBPROP_OWNUPDATEDELETE, true},
// {DBPROP_QUICKRESTART, false},
// {DBPROP_IRowsetResynch, false},
// {DBPROP_CHANGEINSERTEDROWS, false},
// {DBPROP_SERVERDATAONINSERT, false},
// {DBPROP_UNIQUEROWS, false},
// {DBPROP_IMMOBILEROWS, false},
// {DBPROP_IMultipleResults, false},
// {DBPROP_ABORTPRESERVE, true},
// {DBPROP_COMMITPRESERVE, true}
};
for ( i = 0; i < 1; i++ )
{
VariantInit( &m_RowProp[i].vValue );
m_RowProp[i].dwOptions = DBPROPOPTIONS_REQUIRED;
m_RowProp[i].colid = DB_NULLID;
m_RowProp[i].dwPropertyID = crs_props[i].m_PropId;
m_RowProp[i].vValue.vt = VT_BOOL;
m_RowProp[i].vValue.boolVal = crs_props[i].m_Val ?
VARIANT_TRUE : VARIANT_FALSE;
}
m_PropSet.rgProperties = m_RowProp;
m_PropSet.cProperties =
CMOOLEDBQUERY_NOFCOMMANDPROPS;
m_PropSet.guidPropertySet = DBPROPSET_ROWSET;
ret_val = m_ICommandProperties->SetProperties( 1,
&m_PropSet );
m_ICommandProperties->Release();
m_ICommandProperties = 0L;
}
// Set the command text to SQL statment
if ( FAILED( m_ICommandText->SetCommandText( DBGUID_DBSQL, cmd_str
) ) )
{..}
// Execute the command
if ( FAILED( ret_val = m_ICommandText->Execute( NULL,
IID_IRowset,
NULL, m_NumRows,(IUnknown **) &m_Rowset ) ) ) // Resultset pointer
{..}
m_ICommandText->Release();
m_ICommandText = 0L;
.....
.
- Follow-Ups:
- Re: Problem calling a stored procedure
- From: Erland Sommarskog
- Re: Problem calling a stored procedure
- Prev by Date: Re: Data concept
- Next by Date: Re: OLEDB error with SQL 2005
- Previous by thread: Re: Data concept
- Next by thread: Re: Problem calling a stored procedure
- Index(es):
Relevant Pages
|
|