Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old February 20th, 2006, 08:05 PM
blue875@carolina.rr.com
Guest
 
Posts: n/a
Default C# .NET to MS Access OLEDB - Security error

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?




  #2  
Old February 21st, 2006, 05:55 PM
Bri
Guest
 
Posts: n/a
Default Re: C# .NET to MS Access OLEDB - Security error



blue875@carolina.rr.com wrote:[color=blue]
> 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?[/color]

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

  #3  
Old February 22nd, 2006, 06:45 PM
blue875@carolina.rr.com
Guest
 
Posts: n/a
Default Re: C# .NET to MS Access OLEDB - Security error

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?

  #4  
Old February 22nd, 2006, 07:15 PM
Bri
Guest
 
Posts: n/a
Default Re: C# .NET to MS Access OLEDB - Security error


blue875@carolina.rr.com wrote:[color=blue]
> 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?[/color]

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.