?
Solved

Permissions when connecting to an Access DB with ASP.NET

Posted on 2005-03-31
18
Medium Priority
?
381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

765 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