locked
'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' fail RRS feed

  • Question

  • I am a newbie to c#

     

    I have a simple statements to connect to database, execute a query and display in the listbox

     

    string strConnection = "Server=XXX01LXP73406X6;Integrated Security=true;Initial Catalog=AdventureWorks;";

    string strCmd = "select ProgramName,ProgramType from ChangeControl";
    SqlDataAdapter dataAdapter = new SqlDataAdapter(strCmd, strConnection);
    DataSet dataset = new DataSet();DataTable dataTable = dataset.Tables[0];
    dataAdapter.Fill(dataset, "ChangeControl"); //changecontrol is the table name

    foreach (DataRow row in dataTable.Rows) //lbversion is a listbox
    {
        lbVersion.Items.Add(row["ProgramName"] + "-->" + row["ProgramType"]);

    }

     

     

    I get an error while connecting to database.i am using windows authentication and when i connect to the database directly it works.

     

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

     

     

    Please advice. I appreciate all your help

     

    Thanks,

    Kayal.

     

     

     

    Wednesday, March 5, 2008 10:55 PM

Answers

  • I'm working on my local machine. I changed the .net configuration 2.0 settings in the control panel under administrative tools. In .NET Framework 2.0 configuration, Expand the runtime security policy, expand machine, expand code groups, right click all_code, go to properties, go to permission tab and modified nothing to Full Trust.It worked.

    Wednesday, March 12, 2008 5:04 PM

All replies

  •  

    You don't have the CAS necessary to connect to the sql server. Are you executing the application from a network share? Try giving your application a strong name. Here's a blog entry with more information:

     

    http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx

    Thursday, March 6, 2008 12:30 AM
  • Thanks Chris, Appreciate your help... I read the blog.. Please help me understand what a "strong name" is .. how can i come with that ?

    Thursday, March 6, 2008 1:14 AM
  • Chris,

     

      I did read up on strong names and created .snk file using sn.exe and added the following code in the assemblyinfo.cs

     

    [assembly: AssemblyKeyFile("Testkey.snk")]

     

    the build was successful.. no compilation errrs..

     

    but i still get the same error at run time Sad..

     

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

     

    Please advice

     

    Thanks for your help,

    Kayal

     

     

    Thursday, March 6, 2008 5:34 AM
  • I'm working on my local machine. I changed the .net configuration 2.0 settings in the control panel under administrative tools. In .NET Framework 2.0 configuration, Expand the runtime security policy, expand machine, expand code groups, right click all_code, go to properties, go to permission tab and modified nothing to Full Trust.It worked.

    Wednesday, March 12, 2008 5:04 PM
  • Go to the proyect an then rigth click on mouse, an select properties, and on security tab select "full trust application"

     

    more information...

     

    English:

    http://msdn.microsoft.com/en-us/library/0x4t63kb.aspx

     

    Español:

    http://msdn.microsoft.com/es-es/library/0x4t63kb(VS.80).aspx

    Thursday, December 4, 2008 12:33 AM
  • Thanks Ruben. I am working in 3.5 on a wpf application and your solution worked. Changing the runtime securitu policy did not.
    Friday, August 21, 2009 12:52 AM