Click to See Complete Forum and Search --> : File already in use error


Spectre5000
August 21st, 2001, 09:22 AM
Good morning all! I have a really interesting question that I am hoping someone out there can answer for me.
I am trying to access an MS SQL 7 database using VB. The code I have (and this is just test data) is:



Dim db as Database
Dim rs1 as Recordset
Dim inum as Integer

set db = OpenDatabase("f:\MSSQL7\data\Martin1_Data.MDF")
set rs1 = db.OpenRecordset("select count (*) from name", dbOpenSnapshot)
inum = rs1(0)
MsgBox ("The number is " & inum)





When I go to run this, I am getting the error

Run-Time Error '3045':

Could not use f:\MSSQL7\data\Martin1_Data.MDF. File is already in use.

This is just a test database, and there are only 2 people here in my company that have access to this. I made
sure that the other person wasn't in the database, and that SQL Enterprise manager wasn't opened. I have
the references MS ActiveX Data Objects 2.1 Library, MS ActiveX Data Objects Recordset 2.5 Library, MS DAO 3.6
Library, and MS Data Binding Collection added to this simple project, and I still get the above error.

Can anyone out there tell me why this is happening, and how I can go about solving this error?

phunkydude
August 21st, 2001, 03:50 PM
Wow, I don't know whether you realise that your trying some pretty sticky stuff over there. you don't need to worry about mounting the files that SQL Server uses as physical allocation for your database. Those MDF files are strictly for use by SQL Server.
Check out the exposed interfaces of the ADODB library you have referenced:
Connection - you first need to establish a connection to the database. When you've got a Connection object at your disposal, then you can set the various properties, like Provider, Data Source, etc.
Let us know how you fare.