?
Solved

Permissions when connecting to an Access DB with ASP.NET

Posted on 2005-03-31
18
Medium Priority
?
399 Views
Last Modified: 2008-03-06
I am just learning ASP.NET with 2 years experience in classic ASP.

I'm trying to make a simple connection to an Access Database but recieving the following error:
----------------------------------
The Microsoft Jet database engine cannot open the file 'c:\inetpub\wwwroot\?????\db\authors.mdb'. It is already opened exclusively by another user, or you need permission to view its data.
-----------------------------------

I am developing locally with Win XP and IIS. The code i'm using for the connection is as follows:
------------------------------------
sub Page_Load
     dim dbconn,sql,dbcomm,dbread
     dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("db\authors.mdb")&";")
     dbconn.Open()
     sql="SELECT * FROM Authors"
     dbcomm=New OleDbCommand(sql,dbconn)
     dbread=dbcomm.ExecuteReader()
     authors.DataSource=dbread
     authors.DataBind()
     dbread.Close()
     dbconn.Close()
end sub
----------------------------------------

The error message says that the database is open but i know that this is not the case, and i have also checked the permissions for the .mdb file and these appear to be correct.

I wondered whether their is a permissions setting that can be used in the connection string?

Please help!!
0
Comment
Question by:phipsta
  • 7
  • 6
  • 5
18 Comments
 
LVL 2

Expert Comment

by:sumo_the_cat
ID: 13670652
Not 100% about this as I haven't ever tried to access Access from ASP.NET, but it is probably that "user" under which ASP.NET runs has less permissions than the standard windows user.  For example, in SQL Server on XP I give the MACHINENAME/ASPNET user permissions on the database.
0
 
LVL 2

Expert Comment

by:sumo_the_cat
ID: 13670686
I would try to add the ASPNET user to the list of users which have permissions on the mdb (right-click on the mdb, security tab and add user, type ASPNET in the search box and Add. Hope that works!
0
 
LVL 2

Expert Comment

by:sumo_the_cat
ID: 13670722
Oh, and turn on Option Strict. This will help you learn .NET better. You should declare the type of your variables explicitly, e.g.
Dim dbConn As OleDbConnection
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:phipsta
ID: 13670826
Thanks for your help but i was unable to find any ASPNET Users.
Both Guest and SYSTEM have full control.

Any other idea's??
0
 
LVL 2

Expert Comment

by:sumo_the_cat
ID: 13670841
If you've got everything installed properly on XP there must be an ASPNET machine account. Look in Computer Management > Users. Do your ASP.NET applications work (apart from the db connection problem)?
0
 

Author Comment

by:phipsta
ID: 13670844
Could you provide me with more information on 'Option Strict', this sounds very useful.

Is this similar to <%OPTION EXPLICIT%> in ASP??
0
 
LVL 2

Expert Comment

by:sumo_the_cat
ID: 13670855
Are you using Visual Studio?
0
 
LVL 9

Accepted Solution

by:
Type25 earned 375 total points
ID: 13670867
Yep...  right click your website folder  (probably under wwwroot/yourapp)

choose security > click 'Add' > type in YOURCOMPUTERNAME/ASPNET > Give full control

0
 
LVL 9

Expert Comment

by:Type25
ID: 13670869
Is this similar to <%OPTION EXPLICIT%> in ASP??

identical :)
0
 

Author Comment

by:phipsta
ID: 13670908

Your are right. When viewing the users through 'Computer Management' there is a ASPNET user, but when i right click on the .mdb file and go to Properties > Security > Add  and then type in ASPNET as the object name i get the following dialog box.

An object named "ASPNET" cannot be found??
0
 
LVL 9

Expert Comment

by:Type25
ID: 13671026
prefix it with your computername

>>  type in YOURCOMPUTERNAME/ASPNET > Give full control
0
 

Author Comment

by:phipsta
ID: 13671084
No Joy, still getting:

An object named "COMPUTERNAME/ASPNET" cannot be found??

0
 
LVL 9

Expert Comment

by:Type25
ID: 13671103
replace  "COMPUTERNAME" with *your* computer name....

0
 
LVL 9

Expert Comment

by:Type25
ID: 13671118
failing that....

Click 'Add'  >> Click 'Advanced' >> click 'Locations' >> from that box select your computer name (whatever that may be) >> then click 'Find Now'

It will be in that list
0
 

Author Comment

by:phipsta
ID: 13671132
Ahhh Hhhaaaa!!!!

A classic schoolboy error of putting COMPUTERNAME/ASPNET instead of COMPUTERNAME\ASPNET.

Simple backslash instead of forwardslash.

And that's cracked it!! Thanks for your help and a special thanks for your patients!
0
 
LVL 2

Expert Comment

by:sumo_the_cat
ID: 13671198
Good, I thought it would be a simple permissions issue. But it's not good for a production app to leave full modify permissions on the entire web application folder structure. Now narrow it down to just the mdb if possible.

There is both option explict and option strict in VB.NET; the first is the equivalent to OPTION EXPLICIT.
http://support.microsoft.com/kb/311329/EN-US/

Peter.
0
 
LVL 2

Expert Comment

by:sumo_the_cat
ID: 13671241
Do you know how to split points?
0
 

Author Comment

by:phipsta
ID: 13671413
I think it maybe too late as i have already accepted an answer.

But no i don't or didn't
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question