SqlClientPermission error

G

Guest

hi all
i used this below function to connect to sql server 2k

[SqlClientPermission (SecurityAction.Assert ,Unrestricted=true)]
private void button1_Click(object sender, System.EventArgs e)
{
try
{
SqlClientPermission myPerm = new SqlClientPermission(PermissionState.Unrestricted);
myPerm.Assert();
myPerm.AllowBlankPassword=true;
string str;
str= "data source=sniper;initial catalog=newzolf;persist security info=False;user id=zolf;" +
"password=1;packet size=4096";
SqlConnection cnn=new SqlConnection(str);
SqlCommand cmd=new SqlCommand("select * from article",cnn);
cnn.Open();
MessageBox.Show("3");
DataSet ds=new DataSet();
MessageBox.Show("4");
SqlDataAdapter da=new SqlDataAdapter(cmd);
MessageBox.Show("5");
da.Fill(ds);
MessageBox.Show("Sucess");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
when run application on own computer work truly
but when copy the EXE file to shred folder this error accoured

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

why this error accour?

"i am used SqlClientPermission "

thanx in advance.
 
J

Jon Skeet [C# MVP]

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

why this error accour?

When you run code from the network, by default it won't be trusted as
much as purely local apps. If you want to change that, go into your
administrative tool for the computer and change the .NET configuration.
 
G

Guest

Thanx for your answe
but how can set .net SqlClientPermission in runtime
my code not wor
[SqlClientPermission (SecurityAction.Assert ,Unrestricted=true)
private void button1_Click(object sender, System.EventArgs e

tr

SqlClientPermission myPerm = new SqlClientPermission(PermissionState.Unrestricted)
myPerm.Assert();
myPerm.AllowBlankPassword=true
string str
str= "data source=sniper;initial catalog=newzolf;persist security info=False;user id=zolf;"
"password=1;packet size=4096"
SqlConnection cnn=new SqlConnection(str)
SqlCommand cmd=new SqlCommand("select * from article",cnn)
cnn.Open()
MessageBox.Show("3")
DataSet ds=new DataSet()
MessageBox.Show("4")
SqlDataAdapter da=new SqlDataAdapter(cmd)
MessageBox.Show("5")
da.Fill(ds)
MessageBox.Show("Sucess")

catch(Exception ex

MessageBox.Show(ex.Message)
 
G

Guest

Thanx for your answe
but how can set .net SqlClientPermission in runtime
my code not wor
[SqlClientPermission (SecurityAction.Assert ,Unrestricted=true)
private void button1_Click(object sender, System.EventArgs e

tr

SqlClientPermission myPerm = new SqlClientPermission(PermissionState.Unrestricted)
myPerm.Assert();
myPerm.AllowBlankPassword=true
string str
str= "data source=sniper;initial catalog=newzolf;persist security info=False;user id=zolf;"
"password=1;packet size=4096"
SqlConnection cnn=new SqlConnection(str)
SqlCommand cmd=new SqlCommand("select * from article",cnn)
cnn.Open()
MessageBox.Show("3")
DataSet ds=new DataSet()
MessageBox.Show("4")
SqlDataAdapter da=new SqlDataAdapter(cmd)
MessageBox.Show("5")
da.Fill(ds)
MessageBox.Show("Sucess")

catch(Exception ex

MessageBox.Show(ex.Message)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top