Link to home
Start Free TrialLog in
Avatar of phipsta
phipsta

asked on

Permissions when connecting to an Access DB with ASP.NET

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!!
Avatar of sumo_the_cat
sumo_the_cat

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.
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!
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
Avatar of phipsta

ASKER

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

Any other idea's??
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)?
Avatar of phipsta

ASKER

Could you provide me with more information on 'Option Strict', this sounds very useful.

Is this similar to <%OPTION EXPLICIT%> in ASP??
Are you using Visual Studio?
ASKER CERTIFIED SOLUTION
Avatar of Type25
Type25

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is this similar to <%OPTION EXPLICIT%> in ASP??

identical :)
Avatar of phipsta

ASKER


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??
prefix it with your computername

>>  type in YOURCOMPUTERNAME/ASPNET > Give full control
Avatar of phipsta

ASKER

No Joy, still getting:

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

replace  "COMPUTERNAME" with *your* computer name....

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
Avatar of phipsta

ASKER

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!
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.
Do you know how to split points?
Avatar of phipsta

ASKER

I think it maybe too late as i have already accepted an answer.

But no i don't or didn't