How to set command properties in VC++

How to set command properties in VC++

Post by Roger Austi » Tue, 30 Jul 2002 20:54:34



I am using the Oracle OLEDB provider and need to set the
PLSQLRSet property to 1 to return a rowset. If I add this
property to the connection string it works OK but the
Oracle documentation says don't do that, use a command
object property instead. It then gives a VB example of how
to do this, ie...
 objCmd.Properties("PLSQLRSet") = TRUE.

BUT I am using VC++ and ADO smart pointers so how do I set
a command property?

I assume I need to create a new property and add it to the
properties collection, but the methods exposed by
_PropertiesPtr and _PropertyPtr, do not seem (to me
anyway!) to provide enough functionality to create a named
property and add it to a collection.

If you have done this, please advise.
Roger

 
 
 

How to set command properties in VC++

Post by Roy L Fin » Wed, 31 Jul 2002 10:24:38


Roger,

the Properties object is a collection of the Command object.

try this:

_CommandPtr cmd;
...
cmd->Properties->GetItem("PLSQLRSet")->Value = true;

regards
roy fine


Quote:> I am using the Oracle OLEDB provider and need to set the
> PLSQLRSet property to 1 to return a rowset. If I add this
> property to the connection string it works OK but the
> Oracle documentation says don't do that, use a command
> object property instead. It then gives a VB example of how
> to do this, ie...
>  objCmd.Properties("PLSQLRSet") = TRUE.

> BUT I am using VC++ and ADO smart pointers so how do I set
> a command property?

> I assume I need to create a new property and add it to the
> properties collection, but the methods exposed by
> _PropertiesPtr and _PropertyPtr, do not seem (to me
> anyway!) to provide enough functionality to create a named
> property and add it to a collection.

> If you have done this, please advise.
> Roger


 
 
 

How to set command properties in VC++

Post by Roger Austi » Wed, 31 Jul 2002 19:24:51


Roy,

Thanks for that. In my code _variant_t's are expected so I
used...
_variant_t  vName("PLSQLRSet"), vData((long)1);
m_adoCmd->Properties->GetItem(vName)->Value = vData;

This works fine.
Rgds,  Roger

>-----Original Message-----
>Roger,

>the Properties object is a collection of the Command
object.

>try this:

>_CommandPtr cmd;
>....
>cmd->Properties->GetItem("PLSQLRSet")->Value = true;

>regards
>roy fine



>> I am using the Oracle OLEDB provider and need to set the
>> PLSQLRSet property to 1 to return a rowset. If I add
this
>> property to the connection string it works OK but the
>> Oracle documentation says don't do that, use a command
>> object property instead. It then gives a VB example of
how
>> to do this, ie...
>>  objCmd.Properties("PLSQLRSet") = TRUE.

>> BUT I am using VC++ and ADO smart pointers so how do I
set
>> a command property?

>> I assume I need to create a new property and add it to
the
>> properties collection, but the methods exposed by
>> _PropertiesPtr and _PropertyPtr, do not seem (to me
>> anyway!) to provide enough functionality to create a
named
>> property and add it to a collection.

>> If you have done this, please advise.
>> Roger

>.

 
 
 

How to set command properties in VC++

Post by Roy L Fin » Thu, 01 Aug 2002 05:40:02


Roger,

your correct about the _vatiant_t -- but there is a c-tor for the _variant_t
from a boolean, so the compiler will generate one for you inline...

if you single-step through this line of code in the de* - you see it is
doing exactly what you did...
cmd->Properties->GetItem("PLSQLRSet")->Value = true;

glad your code is working..
rlf


> Roy,

> Thanks for that. In my code _variant_t's are expected so I
> used...
> _variant_t  vName("PLSQLRSet"), vData((long)1);
> m_adoCmd->Properties->GetItem(vName)->Value = vData;

> This works fine.
> Rgds,  Roger

> >-----Original Message-----
> >Roger,

> >the Properties object is a collection of the Command
> object.

> >try this:

> >_CommandPtr cmd;
> >....
> >cmd->Properties->GetItem("PLSQLRSet")->Value = true;

> >regards
> >roy fine



> >> I am using the Oracle OLEDB provider and need to set the
> >> PLSQLRSet property to 1 to return a rowset. If I add
> this
> >> property to the connection string it works OK but the
> >> Oracle documentation says don't do that, use a command
> >> object property instead. It then gives a VB example of
> how
> >> to do this, ie...
> >>  objCmd.Properties("PLSQLRSet") = TRUE.

> >> BUT I am using VC++ and ADO smart pointers so how do I
> set
> >> a command property?

> >> I assume I need to create a new property and add it to
> the
> >> properties collection, but the methods exposed by
> >> _PropertiesPtr and _PropertyPtr, do not seem (to me
> >> anyway!) to provide enough functionality to create a
> named
> >> property and add it to a collection.

> >> If you have done this, please advise.
> >> Roger

> >.

 
 
 

1. Setting the Properties of an ADO Recordset before it is opened (VC++)

Hi all, I have fallen foul of the problem listed in
http://support.microsoft.com/support/kb/articles/q187/9/42.asp (included at
the bottom) where I am using ADO transactions and am trying to manipulate
some recordsets after commit or rollback. If I use:

  fn_TESTHR(m_rsJobsPending.CreateInstance(__uuidof(Recordset)));
  m_rsJobsPending->Properties->Item["Preserve On Commit"]->PutValue(true);

m_rsJobsPending->Open(bstr_t(strCommand.c_str()),m_cnMain.GetInterfacePtr(),
adOpenKeyset,adLockOptimistic,adCmdText);

COM Error: -2146825023-Unknown error 0x800A0CC1-ADODB.Properties-Item cannot
be found in the collection corresponding to the requested name or ordinal

Now this seems obvious as the open command hasn't happened yet and the
properties probably havn't been initialised, but the knowledgebase article
tells me that this must be done before the recordset is opened ...
afterwards it is readonly. It seems that I need a 'PutItem' command from the
properties collection.. but there doesn't seem to be one.Does anyone know if
there is a way of adding a property to a Recordset object.. do I have to
instatiate it myself? Can anyone give me any sample code to go on? There
doesn't seem to be any documentation of the Properties collection for VC++
.. if anyone can point me to some, that may also help.

Many Thanks!
 -=- Brett
If only the ADO docs for VC++ were as good as the ones for VB....

PRB: Catastrophic Error Occurs Referencing ADO Recordset

----------------------------------------------------------------------------
----
The information in this article applies to:

ActiveX Data Objects (ADO), versions 2.0, 2.1 SP2
Microsoft OLE DB Provider for SQL Server, version 7.01

----------------------------------------------------------------------------
----

SYMPTOMS
Any operation following a rollback or a commit transaction on a recordset
opened as a serverside cursor, triggers the following error:

Run-time error '-2147418113' Catastrophic failure

CAUSE
Preserving cursors, or in other words, not closing them, is not the SQL
Server or ANSI SQL default. The OLE DB specification does not specify a
default value for these properties because, this behavior can change from
provider to provider.

The Cursor Engine, however, does preserve cursors.

RESOLUTION
Use adUseClient or set the following RecordSet properties to preserve the
cursor:

rs.Properties("Preserve On Commit") = True

rs.Properties("Preserve On Abort") = True
There are three requirements to have these two properties, or any other
preset properties, take effect on a recordset. The two requirements are:

The properties need to be set prior to opening the recordset.

Use the Open method to open the recordset. The Connection and Command
Execute method opens a default Recordset, with all properties preset.

The OLE DB provider must support preserving cursors. The OLE DB Provider for
SQL Server supports preserving cursors on Commit and Abort.

STATUS
This behavior is by design.

2. VB5 Runtime Error : 3421 Data Conversion Error

3. ADOX w/ VC++: How to set column properties?

4. Howto:Handle BCP Errors

5. on server error db trigger to capture offending sql

6. Setting the Properties of an ADO Recordset before it is opened (VC++)

7. Advice on AP 6.1 correllative abort?

8. Read Jet-databas properties with ADO from vc++

9. help:use recordset's dynamic properties in vc++

10. Q188858 Setting the Recordset's dynamic Command Timeout Property does not time out

11. Check whether a Command pointer exists in vc++