SQLClient and SecurityException

G

Guest

Hi,

I'm getting boring and boring with my ado.net code.
I want to write a little vb.net console application that connect to a remote
SQL Server.

I'm using the following code :

Dim cObjConn As SqlClient.SqlConnection
cObjConn = New SqlClient.SqlConnection("Initial
Catalog=myCatalog;UID=mySQLUser;Password=****;Data Source=myServer")
cObjConn.Open()

And every time I run this code, I got the following error on the .open() :

System.Security.SecurityException: Request for the permission of type
System.Dat
a.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0,
Culture=neutra
l, PublicKeyToken=b77a5c561934e089 failed.
at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet
granted
Set, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken
permT
oken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken
permToken,
CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames,
Int32
unrestrictedOverride)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, S
tackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Data.SqlClient.SqlConnectionString.Demand(SqlConnectionString
const
r)
at System.Data.SqlClient.SqlConnection.Open()

I've found a very little example in the VB.Net reskit to connet to
SQLServer. I've updated connection string to connect to my server and it's
works. I really don't know where I'm wrong.

Please help me before I or my computer go throw the window of my office.

Regards
Cyril
 
U

Uri Dor

the security problem you have is a Code Access Security (CAS) problem.
probable causes for this could be that you're running the reskit example
from the local disk but running your code from a network share, or that
the reskit has an installation script that adds permissions.

You can try running your code from a local disk. In any case you can use
the CASPOL.EXE utility at
(windows dir)\Microsoft.NET\Framework\v1.1.4322

to list permissions on both the reskit and your code and to add
permissions to them.

Good luck
 
G

Guest

Hi
I have the same problem and I am going crazy.

Can you please let me know, by a few line of code, how did you solve it?

Thanks
Fabiusmauritius
 
G

Guest

Thank you for your prompt reply.
I want to let you know that i found the FULL SOLUTION to the problem and i
want to share it with you and everyone else is interested to it.

On the CLIENT machine:
- run the "Microsoft .NET Framework 1.1 Wizards"
- double click "Adjust .Net Security"
- check "Make changes to this computer"
- click Next
- select "Local Intranet" and set to FULL TRUST
- click Next
- click Finish

Now you are in business!!! It works as you wanted and your sanity is saved!!!

My best regards
F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top