Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SQL Server security exception

22 views
Skip to first unread message

RSH

unread,
Jan 9, 2006, 4:05:30 PM1/9/06
to

I created a C# class that connects to a SQL Server. I am creating a object
on initialization but I keep getting a security exception:

"Request for the permission of type
'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

I have used this connection string before with no problems...what am I
overlooking here?

Thanks,
Ron


using System;

using System.Collections.Generic;

using System.Text;

using System.Data.SqlClient;

using System.Data;

namespace GeneralTesting

{

class DataClass

{

public SqlConnection SqlConn = new SqlConnection();

public void setConnections()

{

String ConnectionString = "Data Source=TestServer; Integrated Security=SSPI;
Initial Catalog=master";

SqlConn.ConnectionString = ConnectionString;

SqlConn.Open();

}

public DataSet getEmployees(string CompanyID)

{


string strSelectSql = "SELECT FirstName, LastName FROM [" + CompanyID +
"].[dbo].[Employee]";

SqlCommand selectSqlCommand = new SqlCommand(strSelectSql, SqlConn);

SqlDataAdapter sqlData = new SqlDataAdapter(selectSqlCommand);

DataSet dsSelectData = new DataSet();

sqlData.Fill(dsSelectData);

return dsSelectData;

}

}

}

Initialization:

DataClass DC = new DataClass();

DC.setConnections();

DataSet DS = DC.getEmployees("00010145");


Willy Denoyette [MVP]

unread,
Jan 9, 2006, 4:15:19 PM1/9/06
to

"RSH" <way_bey...@yahoo.com> wrote in message
news:OWhfyBWF...@tk2msftngp13.phx.gbl...

Do you happen to run this from a network drive? Then you have to adapt your
code access security settings (CAS) for the share your code resides on, by
default, applications loaded from a network resource cannot access SQL
server. Check MSDN for the caspol utility for more info.

Willy.

RSH

unread,
Jan 9, 2006, 4:38:01 PM1/9/06
to

Nope. The application is running locally, but the SQL server is on the
network. This is very strange because I'm using the same Connection String
here that I am in another application that is in the folder right next to
this one.

I am perplexed.


"Willy Denoyette [MVP]" <willy.d...@telenet.be> wrote in message
news:OinWNHWF...@TK2MSFTNGP14.phx.gbl...

RSH

unread,
Jan 9, 2006, 4:40:09 PM1/9/06
to
System.Security.SecurityException was unhandled
Message="Request for the permission of type
'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
Source="mscorlib"
StackTrace:
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()
at GeneralTesting.DataClass.setConnections()
at GeneralTesting.Program.Main()

"RSH" <way_bey...@yahoo.com> wrote in message
news:OWhfyBWF...@tk2msftngp13.phx.gbl...
>

RSH

unread,
Jan 9, 2006, 5:53:33 PM1/9/06
to
I stand corrected apparently it was on a share.

I am still in quite a pickle here. I have read something on Strong naming
my assemblies...I tried to follow along but I was not able to make sense of
it...I have no DLL files in my project, I was able to make my .snk file but
it gets foggy after that. Is there some sort of Strong naming for Dummies
that I can follow along with? BTW I am running 2.0 framework.

Thanks for any help!
Ron

"RSH" <way_bey...@yahoo.com> wrote in message
news:OWhfyBWF...@tk2msftngp13.phx.gbl...
>

Willy Denoyette [MVP]

unread,
Jan 9, 2006, 6:13:40 PM1/9/06
to
You don't need to strong name your assemblies for this to work, you only
need to grant full trust to your share.
For insatnce to grant Full trust to all of your assemblies loaded from your
share you can go with following command:

CasPol.exe -m -ag 1.2 -url file://Server/MyShare/* FullTrust


It's also possible to be less generous and create a new code group for this
with less privileges than Full trust.

Willy.

"RSH" <way_bey...@yahoo.com> wrote in message

news:%23y27D%23WFGH...@TK2MSFTNGP10.phx.gbl...

RSH

unread,
Jan 10, 2006, 9:00:23 AM1/10/06
to
Thanks for this info.

Is this going to be a problem for deployment also? ...or is this just in a
development environment?

Thanks,
Ron

"Willy Denoyette [MVP]" <willy.d...@telenet.be> wrote in message

news:%23FBJWJX...@TK2MSFTNGP09.phx.gbl...

0 new messages