471,354 Members | 1,246 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 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 1242

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bruce Schechter | last post: by
reply views Thread by Carl Gilbert | last post: by
6 posts views Thread by Daniel Walzenbach | last post: by
5 posts views Thread by James | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.