473,490 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL Server security exception

RSH

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");


Jan 9 '06 #1
6 1283

"RSH" <wa*************@yahoo.com> wrote in message
news:OW**************@tk2msftngp13.phx.gbl...
|
| 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");

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.

Jan 9 '06 #2
RSH

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]" <wi*************@telenet.be> wrote in message
news:Oi**************@TK2MSFTNGP14.phx.gbl...

"RSH" <wa*************@yahoo.com> wrote in message
news:OW**************@tk2msftngp13.phx.gbl...
|
| 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");

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.

Jan 9 '06 #3
RSH
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(Obj ect demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.PermissionSet.Demand()
at System.Data.Common.DbConnectionOptions.DemandPermi ssion()
at System.Data.SqlClient.SqlConnection.PermissionDema nd()
at
System.Data.SqlClient.SqlConnectionFactory.Permiss ionDemand(DbConnection
outerConnection)
at
System.Data.ProviderBase.DbConnectionClosed.OpenCo nnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at GeneralTesting.DataClass.setConnections()
at GeneralTesting.Program.Main()

"RSH" <wa*************@yahoo.com> wrote in message
news:OW**************@tk2msftngp13.phx.gbl...

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");


Jan 9 '06 #4
RSH
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" <wa*************@yahoo.com> wrote in message
news:OW**************@tk2msftngp13.phx.gbl...

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");


Jan 9 '06 #5
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" <wa*************@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
|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" <wa*************@yahoo.com> wrote in message
| news:OW**************@tk2msftngp13.phx.gbl...
| >
| > 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");
| >
| >
| >
| >
| >
| >
|
|
Jan 9 '06 #6
RSH
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]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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" <wa*************@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
|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" <wa*************@yahoo.com> wrote in message
| news:OW**************@tk2msftngp13.phx.gbl...
| >
| > 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");
| >
| >
| >
| >
| >
| >
|
|

Jan 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7227
by: rrober07 | last post by:
Hello, My Setup is I have a Web Server machine(Devweb01), Database SQL Machine(Devsql01), a Client Machine(local machine) I have configured the SQL machine as follows: 1) Added local Aspnet...
5
6545
by: Bruce Schechter | last post by:
I just started to develop an ASP.NET application in vs.net 2003 . But each time I try to execute the application (which is basically empty so far), I get a dialog box titled "Microsoft Development...
0
2422
by: Sam Fields | last post by:
I have found very little regarding the error "Unable to find an entry point named EnumerateSecurityPackagesW in DLL security.dll. ". I have an ASP.NET Web Service being accessed via SSL. I found...
0
1516
by: Carl Gilbert | last post by:
Hi I am trying to get an online gallery to work (www.ngallery.org). I have managed to get it all working on my local host but I can not get it to work on my web space. The site can be found...
6
3762
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
4
13151
by: VB Programmer | last post by:
When I run my ASP.NET 2.0 web app on my dev machine it works perfect. When I precomile it to my web deployment project and then copy the debug files to my web server I get this problem when trying...
0
2974
by: emu | last post by:
Hi All, I have an unmanaged C++ application that references a mixed mode image DLL (mixed managed and unmanaged). Under .NET 1.1 we could trust the dll (the mixed mode dll) by running the...
2
6914
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
5
1915
by: James | last post by:
Hello, I have written a simple logon page that redirects to another page when successful. All works fine on my computer but when I upload it I get the error message below. I have written it...
0
7142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.