By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,079 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,079 IT Pros & Developers. It's quick & easy.

C# .NET to MS Access OLEDB - Security error

P: n/a
When I run this connection, I get a security error.

String connectStr = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"User Id=USER; Password=PASS;" +
@"Data Source=\\SERVER\DIRECTORY\Data.mdb;" +
@"Jet OLEDB:System
Database=\\SERVER\DIRECTORY\SYSTEM.mdw";

connection = new OleDbConnection(connectStr);
connection.Open(); // <=== error!

the error:
Request for the permission of type 'System.Data.OleDb.OleDbPermission,
System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=TOKEN'
failed.

(Keep in mind that anything in all caps here is my own edit, for
security reasons. I assure you, syntax within those areas is correct.)

I've attempted several variations of this connection string, including
Mode = Share Deny None, Persist Security Info = false, and so on. The
database I'm trying to hit is on a server in my network. There is no
password on the database, but my account does have one (included where
PASS is).

I've successfully set up connections within Access forms using these
same connection strings. Why would I have security issues within
VS.NET 2k5?

Feb 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Bri


bl*****@carolina.rr.com wrote:
When I run this connection, I get a security error.

String connectStr = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"User Id=USER; Password=PASS;" +
@"Data Source=\\SERVER\DIRECTORY\Data.mdb;" +
@"Jet OLEDB:System
Database=\\SERVER\DIRECTORY\SYSTEM.mdw";

connection = new OleDbConnection(connectStr);
connection.Open(); // <=== error!

the error:
Request for the permission of type 'System.Data.OleDb.OleDbPermission,
System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=TOKEN'
failed.

(Keep in mind that anything in all caps here is my own edit, for
security reasons. I assure you, syntax within those areas is correct.)

I've attempted several variations of this connection string, including
Mode = Share Deny None, Persist Security Info = false, and so on. The
database I'm trying to hit is on a server in my network. There is no
password on the database, but my account does have one (included where
PASS is).

I've successfully set up connections within Access forms using these
same connection strings. Why would I have security issues within
VS.NET 2k5?


I haven't tried connecting to an MDB via VS.NET or C#. I have done it
via VBScript in an ASP page. The ID and PW are for the Access UserID
that is in the MDW, not the Login ID for Windows (just clarifying). I
did not include the ID and PW in the connection string, but rather
included them on the Connection.Open statement (note that in ASP
Server.MapPath returns the actual path on the server of the relative
path supplied for the file):

strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("\PATH\DATA.mdb") & ";Jet OLEDB:System database=" & _
Server.MapPath("\PATH\DATA.mdw") & ";"
set xConn = Server.CreateObject("ADODB.Connection")
xConn.Open strConn, "UserID", "Password"

Can you try this syntax and see if it works for you? You can find many
good examlpes of connection strings from many languages to many
providers at this site which has helped me a lot:
http://www.carlprothman.net/Default.aspx?tabid=81

--
Bri

Feb 21 '06 #2

P: n/a
C#'s OleDbConnection.Open doesn't take any arguments. It assumes (I
guess) that everything is set up in the ConnectionString property
beforehand. The .Open command is definitely using the connectionString
I send it (I can see it in the Immediate window in VS.NET studio).

I really don't think it's a syntax issue. I've searched several
websites on connection strings, and this seems to follow Access's
syntax. What I'm wondering is what would cause a security issue on an
access database, when the .mdw file is on my computer, no other
programs are using it, and my account is valid? Are there some drivers
I need to configure, or an environment variable perhaps?

Feb 22 '06 #3

P: n/a
Bri

bl*****@carolina.rr.com wrote:
C#'s OleDbConnection.Open doesn't take any arguments. It assumes (I
guess) that everything is set up in the ConnectionString property
beforehand. The .Open command is definitely using the connectionString
I send it (I can see it in the Immediate window in VS.NET studio).

I really don't think it's a syntax issue. I've searched several
websites on connection strings, and this seems to follow Access's
syntax. What I'm wondering is what would cause a security issue on an
access database, when the .mdw file is on my computer, no other
programs are using it, and my account is valid? Are there some drivers
I need to configure, or an environment variable perhaps?


I agree, your syntax should work. Have you tried a test against an
unsecured MDB to make sure that that works? This would eliminate issues
with the Provider and any Windows UserID permissions. If this also fails
then verify that the Windows ID has all rights to the folder(s) that the
MDB and the MDW are in. When Jet opens the MDB and MDW it creates an
associated LDB file (deleted after the last connection closes). If it
can't create, or modify this file then you will get errors.

--
Bri

Feb 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.