Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with opening access database.

Status
Not open for further replies.

jgsteeldev

Programmer
Feb 5, 2004
30
0
0
US
Code:
The Microsoft Jet database engine cannot open the file 'C:\DBName.mdb'. It is already opened exclusively by another user, or you need permission to view its data.
Does anybody know why this is happening?

Here is the code.

Code:
 Dim silpadaConn As OleDbConnection = New OleDbConnection("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
        "ocking Mode=1;Jet OLEDB:Database Password=;Data Source=""C:\DBName.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk T" & _
        "ransactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet " & _
        "OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database" & _
        " Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on" & _
        " Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet " & _
        "OLEDB:Encrypt Database=False")

        Dim selectCMD As OleDbCommand = New OleDbCommand("SELECT intPersonID, txtEmail, txtFirstName, txtLastName, txtPhone, txtWebsite FRO" & _
        "M tblContacts", silpadaConn)

        selectCMD.CommandTimeout = 30

        Dim custDA As OleDbDataAdapter = New OleDbDataAdapter
        custDA.SelectCommand = selectCMD

        Dim custDS As DataSet = New DataSet
        custDA.Fill(custDS, "tblContacts")
        DataGrid1.DataSource = custDS
        DataGrid1.DataMember = "tblContacts"
        DataGrid1.DataBind()

Here we go Royals! Here we go!!!!!
 
The Machine_Name\ASPNET account probably needs read/write permissions to the folder where the database resides.
 
You probably haven't set the relevant permissions for the ASPNET account. Try setting the correct access permissions to this folder from the Security tab of the folder.

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

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
I've been beaten to it by Veep! At least we can see the times the posts were made now!

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

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Anomalies do happen. You've got further to travel to the server. [lol]
 
ASPNET has full control of the folder. Still getting the same error. I am not sure what to do now.

Here we go Royals! Here we go!!!!!
 
Why don't you simplify things a bit for starters and start from there. You don't necessarily need a connection or command object when using a DataAdapter. If you do use a command object then you do need a connection object and need to call the Open() method on it before you can use the command object. Since you are using a DataAdapter try it with a connection string and a command string.
Code:
Dim strConn As String = _
         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=C:\DBName.mdb;" & _
         "User ID=Admin;" & _
         "Password="
Dim strSql = "SELECT intPersonID, txtEmail, txtFirstName, _"
& "txtLastName, txtPhone, txtWebsite FROM tblContacts" 
Dim custDA As OleDbDataAdapter = New OleDbDataAdapter(strSql,strConn)
Dim custDS As DataSet = New DataSet
        custDA.Fill(custDS, "tblContacts")
        DataGrid1.DataSource = custDS
        DataGrid1.DataMember = "tblContacts"
        DataGrid1.DataBind()

 
Not sure if you are but if you are using a Windows 2003 machine you will need to add permissions for the Network Service account (faq855-5807).

If not, then make sure it isn't "opened exclusively by another user".

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

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Actually the project was just a take homw type test for from a job interview. The place i applied at runs sql server anyway so I just quit trying to use access and switched to sql server. I don't have time to mess with access right now. When switched to SQL the application works wonders. Thanks for the advice though.

Veep, I had already tried the method you posted up ther. I got the same error message. For some reason I couldn't open the stupid mdb.

ca8msm, not runing 2003 and I the database is stored on my machine at home it is not on a network so "opened exclusively by another user" is not possible.

Thanks anyway.

Here we go Royals! Here we go!!!!!
 
Maybe they gave you a database that wouldn't open and that was part of the test. [lol]
 
:) That would be a good test but I created the access database. They told me to use what I wanted. The only reason I went with access was so that I could send the db with the code. So that they wouldn't have to create a database.But I am not wasting anymore time on it.


Thanks though.

Here we go Royals! Here we go!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top