Data Access Problem when importing custom file

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Data Access Problem when importing custom file

    Hi,

    I have an aspx file that creates a custom class object and calls a
    method which should return a DataSet. It throws a:

    Description: The application attempted to perform an operation not
    allowed by the security policy. To grant this application the required
    permission please contact your system administrator or change the
    application's trust level in the configuration file.

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

    Error.

    When the methods from DB.cs is included in the aspx file it works
    ok!!!

    What is the problem? And how can I resolve it so that I have code
    seperationg.

    Here are the files in more detail:

    aspx page:
    <%@ Import Namespace="DBAccess" %>
    protected void Page_Load(Object Src, EventArgs E)
    {
    DB db = new DB();
    DataSet ds = db.GetDataSet("spu_Marketer", "Marketer");

    MyDataGrid.DataSource=ds.Tables["Marketer"].DefaultView;
    MyDataGrid.DataBind();

    AnotherDataGrid.DataSource=ds.Tables["Marketer"].DefaultView;
    AnotherDataGrid.DataBind();

    }

    DB.cs

    namespace DBAccess
    {
    /// <summary>
    /// ADO.NET data access using the SQL Server Managed Provider.
    /// </summary>
    public class DB
    {
    // connection to data source
    private SqlConnection con;

    private void OpenCon()
    {
    if (con == null)
    {
    con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    con.Open();
    }
    }

    public DataSet GetDataSet(string procName, string sString)
    {
    OpenCon();
    SqlDataAdapter sdc = new SqlDataAdapter(procName, con);
    sdc.SelectCommand.CommandType = CommandType.StoredProcedure;

    DataSet ds = new DataSet();
    sdc.Fill(ds, sString);

    return ds;
    }

    }
    }
    Alex Guest

  2. Similar Questions and Discussions

    1. Help importing excel file into Access DB
      I need to import an excel file into an access database. I got the below code from a forum on another site, but it is not working. I get an error...
    2. problem in binding xml file data to datagrid xml file isgenerated through JSP file
      problem it that i am creating xml file using JSP file and i want to bind DataGrid with xml file data that is created using JSP but it will not Bind...
    3. Problem with data access
      i had a working site with iis5 winxp professional on a p4 machine. suddenly i am having problems with and the asp pages which have some updating...
    4. Getting data out of a text file and putting it in an Access DB
      Hi All First of all I want to thank you all for your time and patience this weekend. Much appreciated. Secondly, I'm stuck with the...
    5. Problem importing .wav file
      "Monstaa" <webforumsuser@macromedia.com> wrote in message news:bgo6oo$fn5$1@forums.macromedia.com... of wavs that I made myself (they are voice...
  3. #2

    Default Re: Data Access Problem when importing custom file

    Alex,

    Are you using integrated security on the sql server?

    If you gave the aspnet account (or another that the web site is running
    under) access to the sql server and are using integrated security it is most
    likely that the user account that you are calling this code from is
    different and it doesn't have access.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche


    "Alex" <alex@hotpop.com> wrote in message
    news:c5c70ed9.0308120459.7aa264a0@posting.google.c om...
    > Hi,
    >
    > I have an aspx file that creates a custom class object and calls a
    > method which should return a DataSet. It throws a:
    >
    > Description: The application attempted to perform an operation not
    > allowed by the security policy. To grant this application the required
    > permission please contact your system administrator or change the
    > application's trust level in the configuration file.
    >
    > Exception Details: System.Security.SecurityException: Request for the
    > permission of type System.Data.SqlClient.SqlClientPermission,
    > System.Data, Version=1.0.5000.0, Culture=neutral,
    > PublicKeyToken=b77a5c561934e089 failed.
    >
    > Error.
    >
    > When the methods from DB.cs is included in the aspx file it works
    > ok!!!
    >
    > What is the problem? And how can I resolve it so that I have code
    > seperationg.
    >
    > Here are the files in more detail:
    >
    > aspx page:
    > <%@ Import Namespace="DBAccess" %>
    > protected void Page_Load(Object Src, EventArgs E)
    > {
    > DB db = new DB();
    > DataSet ds = db.GetDataSet("spu_Marketer", "Marketer");
    >
    > MyDataGrid.DataSource=ds.Tables["Marketer"].DefaultView;
    > MyDataGrid.DataBind();
    >
    > AnotherDataGrid.DataSource=ds.Tables["Marketer"].DefaultView;
    > AnotherDataGrid.DataBind();
    >
    > }
    >
    > DB.cs
    >
    > namespace DBAccess
    > {
    > /// <summary>
    > /// ADO.NET data access using the SQL Server Managed Provider.
    > /// </summary>
    > public class DB
    > {
    > // connection to data source
    > private SqlConnection con;
    >
    > private void OpenCon()
    > {
    > if (con == null)
    > {
    > con = new
    SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    > con.Open();
    > }
    > }
    >
    > public DataSet GetDataSet(string procName, string sString)
    > {
    > OpenCon();
    > SqlDataAdapter sdc = new SqlDataAdapter(procName, con);
    > sdc.SelectCommand.CommandType = CommandType.StoredProcedure;
    >
    > DataSet ds = new DataSet();
    > sdc.Fill(ds, sString);
    >
    > return ds;
    > }
    >
    > }
    > }

    S. Justin Gengo Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139