From: jc on
Hello,

I have an MFC application that uses a MS Access database.
I declare a CDatabase object and pass a connection string.
The database Opens OK. I declare two recordset objects,
and the two recordsets Open OK.
I pass a NULL value, when I open the two recordsets.

The problem occurs, when I try to open a second Access database.
The second database has the same schema, but different data.

Steps :
1. Close the two recordsets.
2. Close the database object.
3. Open the database object with new connection string -OK
4. Examine the database name with GetDatabaseName method - OK
5. Open the two recordsets - OK.

Problem:
However, when I examine the recordset values, the recordset
values are from the first database and not from the second database.

How do I get the recordsets to use the values from the second
database object?

TIA
-jc
From: Scott McPhillips [MVP] on
"jc" <jc(a)discussions.microsoft.com> wrote in message
news:03052809-1B34-49A6-9666-7A9E26351E3D(a)microsoft.com...
> Hello,
>
> I have an MFC application that uses a MS Access database.
> I declare a CDatabase object and pass a connection string.
> The database Opens OK. I declare two recordset objects,
> and the two recordsets Open OK.
> I pass a NULL value, when I open the two recordsets.
>
> The problem occurs, when I try to open a second Access database.
> The second database has the same schema, but different data.
>
> Steps :
> 1. Close the two recordsets.
> 2. Close the database object.
> 3. Open the database object with new connection string -OK
> 4. Examine the database name with GetDatabaseName method - OK
> 5. Open the two recordsets - OK.
>
> Problem:
> However, when I examine the recordset values, the recordset
> values are from the first database and not from the second database.
>
> How do I get the recordsets to use the values from the second
> database object?
>
> TIA
> -jc


The CDatabase object does buffering. Try creating a new CDatabase object
just before you open it, and destroy that object after you close it.

--
Scott McPhillips [VC++ MVP]

From: jc on
Scott,

Thank you for replying to my posting.

Deleting the CDatabase object helped.
Also, I had to delete the CRecordSet objects.

Thanks again,
-jc
From: jc on
Scott,

I am getting a "sharing violation" error, when I switch between
opening and closing different Access database files. Also,
I delete the object.

I inserted a "Sleep" method, after I finished closing and deleting the
database and recordset objects. It seems to have eliminated the
problem.

Is there some type of race condition, when opening and closing
the database and recordset objects?

TIA
-jc

"jc" wrote:

> Scott,
>
> Thank you for replying to my posting.
>
> Deleting the CDatabase object helped.
> Also, I had to delete the CRecordSet objects.
>
> Thanks again,
> -jc