473,376 Members | 1,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,376 software developers and data experts.

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 1281

"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
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
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
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.