PDA

Click to See Complete Forum and Search --> : Running Application From Network Drive


Developer2007
Oct 13th, 2008, 08:59 PM
Need help from the guru's out there,

I am trying to run a .net application from a network drive, the application starts up fine but as soon as the application accesses SQL Server for data I get the following error.

System.Exception: System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.PermissionSet.Demand()
at System.Data.Common.DbConnectionOptions.DemandPermission()
at System.Data.SqlClient.SqlConnection.PermissionDemand()
at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
......etc

The application works fine on my local computer and also runs fine when running directly from the machine hosting the network share folder. The only time it won't work is if I try to run the app accross the network (Shortcut to exe file stored on mapped drive) and try to access the database.

I'm currently running SQL Server 2005 on sbs server 2003, visual studio 2008, vb.net framework 2.0

I have tried the following links and multiple other links but still no success. Also tried the "Caspol.exe" links. but with no success.
http://weblogs.sqlteam.com/jhermiz/archive/2007/08/14/60284.aspx

If someone has solved this problem before please help.


Thanks in advance.

gep13
Oct 13th, 2008, 09:18 PM
Hey,

From what I understand when you run an application, the .Net Framework decides what code group the assembly should run in based on the evidence that is provided to it, and based on that, your assembly is assigned a permission set. It looks like your assembly is being assigned a permission set which does not include the SqlClientPermission, and as a result, it is not able to execute the commands within your application.

In order to give your assembly more permissions, you need to change the evidence associated with your assembly, and one way of doing this, as described in the link that you provided, is to provide a strong name for your assembly.

Have you done this?

I would have thought after doing this that it should have worked.

Gary

Developer2007
Oct 13th, 2008, 09:40 PM
thanks for the quick reply,

I tried the two methods listed on that link to the best of my knowledge but by the sounds of things I didn't implement them correctly.

when I tried to add this line to the assembly

<Assembly: AssemblyKeyFile("\\ServerName\MyFolder\mykey.snk")>

It was underlined in green and I get this warning message.

Use command-line option '/keyfile' or appropriate project settings instead of 'System.Reflection.AssemblyKeyFileAttribute'.

The application still built fine tho. So I must have went wrong somewhere.

So I tried adding this in the Project ---> properties --> signing. But still no luck.

Can you point me in the right direction.

gep13
Oct 13th, 2008, 09:52 PM
Hey,

Hopefully these couple of links should set you on your way:

http://msdn.microsoft.com/en-us/library/xc31ft41.aspx
http://support.microsoft.com/kb/302340

Gary