Connect to Access db from VC#

  • Thread starter Thread starter Mohammed AlQuraishi
  • Start date Start date
M

Mohammed AlQuraishi

Hi all,

I'm trying to connect to an MS Access database using ADO.NET and C#, but I'm
getting the dreaded "Microsoft Jet database engine cannot open the file 'x'.
It is already opened exclusively by another user, or you need permission to
view its data."

Any ideas as to why? I set up a connection using Jet 4.0 and I'm able to
open the database from within VC#.

Thanks for any help!
 
P.S. I tried setting impersonation to true and now I'm getting an
"unspecified error"... It still doesn't work :(
 
Sounds like a permissions problem.

If the .mdb file is located on the same machine as the webserver, give the
ASPNet user account Read/Write NTFS permissions to the folder that the .mdb
file is in, and the Creator/Owner user Full Control.

Cheers
Ken

: Hi all,
:
: I'm trying to connect to an MS Access database using ADO.NET and C#, but
I'm
: getting the dreaded "Microsoft Jet database engine cannot open the file
'x'.
: It is already opened exclusively by another user, or you need permission
to
: view its data."
:
: Any ideas as to why? I set up a connection using Jet 4.0 and I'm able to
: open the database from within VC#.
:
: Thanks for any help!
:
:
 
Well I did set impersonation to true, which, if what I gathered from the
document is correct, ought to be sufficient to resolve the problem. However,
I am getting a new error now, namely "Unspecific error has occurred"...

Any ideas? Thank you very much!
 
Well, I'm pretty sure this is a total newbie problem, but I don't think it's
any of the issues you listed (although I can obviously be wrong.)

The db is running on my C drive, so it's totally local, and I have in fact
created a new dummy db without anything just to test that it's
working--still nothing. Now what do you mean am I using ASP.NET? I'm a bit
unclear actually as to the distinction between ASP.NET and ADO.NET, but I
think I'm using both. Basically I've made a project using VC#, added a
dbOleConnection and dbOleCommand objects, and then having been trying to
open the dbOleConnection object and got the error I mentioned.

I just checked on the ASPNET permissions, and made it a member of
administrators (this is all local so I'm not worried about security yet,)
and still the same issue. So I don't think it's that..I could move to MSDE
or other options, but this was just meant to be a tiny tiny app that I'm
using at home, and it's just ballooning into a far bigger problem than it
should. I would rather not have to do that YET, but I suppose if push comes
to shove I will....

Thanks a plenty!
 
Well I have an dbOleConnection object set at design time to:

Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data
Source=C:\Inetpub\wwwroot\Flows\db1.mdb;Mode=ReadWrite|Share Deny
None;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry
Path="";Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=5;Jet
OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet
OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;Jet OLEDB:SFP=False

And my dummy function simply tries to open the oleDbConnection object by
invoking the Open method. That's it.

This is the error I'm getting:


Server Error in '/Flows' Application.
----------------------------------------------------------------------------
----

Unspecified error
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Unspecified error

Source Error:

Line 62: private void Button1_Click(object sender, System.EventArgs e)
Line 63: {
Line 64: oleDbConnection1.Open();
Line 65: System.Data.OleDb.OleDbDataReader myReader =
oleDbCommand1.ExecuteReader();
Line 66: while (myReader.Read())

Source File: c:\inetpub\wwwroot\flows\webform1.aspx.cs Line: 64

Stack Trace:

[OleDbException (0x80004005): Unspecified error]
System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
System.Data.OleDb.OleDbConnection.InitializeProvider()
System.Data.OleDb.OleDbConnection.Open()
Flows.WebForm1.Button1_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\flows\webform1.aspx.cs:64
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()




Thanks again for any help!
 
You've got to be kidding me! That's all I had to do!!!!

Why on earth do they make it so difficult? Such a simple task and it took me
a whole day! Wow thank you very much! Really appreciate the help!!!

Mohammed
 
Back
Top