Sunday, February 26, 2012

Driver caching db?

Hello,
I'm not sure if this message belongs in microsoft.public.sqlserver.msde
or is more appropriate here. Please accept my apologies if I have the
wrong list.
I've written ODBC source in C++ that accesses an MSDE instance on a
local machine. I perform the usual steps:
1. Allocate an SQLHENV
2. Allocate the SQLHDBC
3. Connect
4. Execute a statement to "use " my database
5. Issue a simple query
6. Process results
7. Disconnect SQLHDBC
8. Free SQLHDBC
9. Free SQLHENV
10. Exit application
Then I try to attach to the database in SQL Server Enterprise Manager
which returns the following error:
"Error 5123: CREATE FILE encountered operating system error 32 (The
process cannot access the file because it is being used by another
process.) while attempting to open or create the physical file:
'C:\mydb.mdf'.
Do I need to do something different to force the driver to unload the
database when the application ends?
Thanks,
JohnThe driver does not touch the database file directly. The SQL Server
process will open (and lock) the database file.
Is the database hosted in a different SQL instance, than the one you are
connecting to in Enterprise Manager?
Brannon
"JohnD" <john_nospam@.tech-testing.com> wrote in message
news:hqpUc.8189$YU1.7939@.newssvr22.news.prodigy.com...
> Hello,
> I'm not sure if this message belongs in microsoft.public.sqlserver.msde
> or is more appropriate here. Please accept my apologies if I have the
> wrong list.
> I've written ODBC source in C++ that accesses an MSDE instance on a
> local machine. I perform the usual steps:
> 1. Allocate an SQLHENV
> 2. Allocate the SQLHDBC
> 3. Connect
> 4. Execute a statement to "use " my database
> 5. Issue a simple query
> 6. Process results
> 7. Disconnect SQLHDBC
> 8. Free SQLHDBC
> 9. Free SQLHENV
> 10. Exit application
> Then I try to attach to the database in SQL Server Enterprise Manager
> which returns the following error:
> "Error 5123: CREATE FILE encountered operating system error 32 (The
> process cannot access the file because it is being used by another
> process.) while attempting to open or create the physical file:
> 'C:\mydb.mdf'.
> Do I need to do something different to force the driver to unload the
> database when the application ends?
> Thanks,
> John|||Brannon Jones wrote:
> Is the database hosted in a different SQL instance, than the one you are
> connecting to in Enterprise Manager?
Yes it is. I'm assuming (really I didn't know this...) that this makes
a different?
The application is using a default SQLSERVER instance and the attaching
is occurring in another DBINSTANCE.|||I don't think you can attach a single database to two different SQL
instances. The first instance that loads the database locks it for
exclusive access. So the second instance that tries to load the database
wont be able to.
Brannon
"JohnD" <john_nospam@.tech-testing.com> wrote in message
news:d6vUc.1687$lY3.1035@.newssvr23.news.prodigy.com...
> Brannon Jones wrote:
> Yes it is. I'm assuming (really I didn't know this...) that this makes
> a different?
> The application is using a default SQLSERVER instance and the attaching
> is occurring in another DBINSTANCE.|||Brannon Jones wrote:

> I don't think you can attach a single database to two different SQL
> instances. The first instance that loads the database locks it for
> exclusive access. So the second instance that tries to load the database
> wont be able to.
Which explains why I have to stop the instance in order for the other
instance to attach to it.
Thank you very much Brannon for the clarification.

No comments:

Post a Comment