Home > Archive > MS SQLCE > April 2005 > Using CCommand object to execute an INSERT









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using CCommand object to execute an INSERT
Rafael

2005-04-07, 8:02 pm

Hi!!

I have a problem in my code and I can't resolve it.

I have to do many INSERT queries, and I need to execute them using the
CCommand::Open method (I know I have the option insertin data through CTable
object). I do them very well, successfully, but a get an error, when I am
"debugging" my code, after I close the program (it is an access violation
error, perhaps a memory leak).

I put my code below (I am using some classes built by Mr. João Paulo
Figueira, proposed in the article
http://www.pocketpcdn.com/articles/atl_ole_db.html ). Please, could anyone
help me?


CoInitializeEx( NULL, COINIT_MULTITHREADED
);

CSqlCeDataSource objSqlCeDataSource;
CSession *pntSession;
HRESULT hr = objSqlCeDataSource.Open( DATABASE_FILE_NAME, PASSWORD );

pntSession = new CSession();
hr = pntSession->Open( objSqlCeDataSource );

CCommand<CDynamicAccessor, CRowsetPosition> objCommandExecQuery;


/*
I already have tried using a CCommand<CNoAccessor, CNoRowset> object, and I
got the same result, even trying to call other CCommand::Open method.
*/

hr = objCommandExecQuery.Open( *pntSession, MY_INSERT_QUERY, NULL, NULL,
DBGUID_DBSQL, false );

objCommandExecQuery.Close();
objCommandExecQuery.ReleaseCommand();

pntSession->Close();
delete pntSession;
objSqlCeDataSource.Close();

Joćo Paulo Figueira [eMVP]

2005-04-07, 8:02 pm

Hi,
Make sure you have the latest version of the atldbcli_ce.h file. You can
find it here:
http://www.codeproject.com/useritems/sqlcespy.asp

To issue INSERT satements, you can use CCommand<CNoAccessor, CNoRowset>.
This way you skip the overhead of both the accessor and the rowset class:
they are not needed.
--
Joćo Paulo Figueira
Embedded MVP

"Rafael" <Rafael@discussions.microsoft.com> wrote in message
news:31D74BFD-253A-48F1-9824- DB39FF43388D@microso
ft.com...
> Hi!!
>
> I have a problem in my code and I can't resolve it.
>
> I have to do many INSERT queries, and I need to execute them using the
> CCommand::Open method (I know I have the option insertin data through
> CTable
> object). I do them very well, successfully, but a get an error, when I am
> "debugging" my code, after I close the program (it is an access violation
> error, perhaps a memory leak).
>
> I put my code below (I am using some classes built by Mr. Joćo Paulo
> Figueira, proposed in the article
> http://www.pocketpcdn.com/articles/atl_ole_db.html ). Please, could anyone
> help me?
>
>
> CoInitializeEx( NULL, COINIT_MULTITHREADED
);
>
> CSqlCeDataSource objSqlCeDataSource;
> CSession *pntSession;
> HRESULT hr = objSqlCeDataSource.Open( DATABASE_FILE_NAME, PASSWORD );
>
> pntSession = new CSession();
> hr = pntSession->Open( objSqlCeDataSource );
>
> CCommand<CDynamicAccessor, CRowsetPosition> objCommandExecQuery;

>
> /*
> I already have tried using a CCommand<CNoAccessor, CNoRowset> object, and
> I
> got the same result, even trying to call other CCommand::Open method.
> */
>
> hr = objCommandExecQuery.Open( *pntSession, MY_INSERT_QUERY, NULL, NULL,
> DBGUID_DBSQL, false );
>
> objCommandExecQuery.Close();
> objCommandExecQuery.ReleaseCommand();
>
> pntSession->Close();
> delete pntSession;
> objSqlCeDataSource.Close();
>



Rafael

2005-04-13, 11:23 am

Hi,

I used the latest version of the atldbcli_ce.h file. And I still have the
same problem. I did a lot of tests. The error doesn't happen if I exchange
the INSERT query by a SELECT one. I also tried to use the
CCommand<CNoAccessor, CNoRowset> (the most indicated, as you said, for insert
queries), and the error also occurs, at the end of my program (I just can see
it while "debugging" it).

Please, do you think my code is correct?

Thanks a lot,

Rafael RabĆŖlo.

"João Paulo Figueira [eMVP]" wrote:

> Hi,
> Make sure you have the latest version of the atldbcli_ce.h file. You can
> find it here:
> http://www.codeproject.com/useritems/sqlcespy.asp
>
> To issue INSERT satements, you can use CCommand<CNoAccessor, CNoRowset>.
> This way you skip the overhead of both the accessor and the rowset class:
> they are not needed.
> --
> João Paulo Figueira
> Embedded MVP
>
> "Rafael" <Rafael@discussions.microsoft.com> wrote in message
> news:31D74BFD-253A-48F1-9824- DB39FF43388D@microso
ft.com...
>
>
>

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com