473,387 Members | 1,541 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,387 software developers and data experts.

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;
}

}
}
Nov 17 '05 #1
5 1553
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:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Alex" <al**@hotpop.com> wrote in message
news:c5**************************@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;
}

}
}

Nov 17 '05 #2
Morning Justin,

Thanks for you post. I'm using a specific user/pwd for the DB as
defined in the connection string. For completeness here it is:
<appSettings>
<add key="ConnectionString"
value="server=SomeServer;database=XXX;uid=XXX;pwd= yy;Trusted_Connection=yes"
/>
</appSettings>
I defined a specific DB user which the asp should use. Remember that
if I take the two files and put the code into the aspx page it works.
Simply cutting and pasting the two methods, and calling the method
directly (not creating the DB object) works.

You are thinking that when I split them accross two files it's trying
to use my WINDOWS username/pass to access the DB? I will look into it.
Where would this setting be?

Do you think it would be better to use a codebehind page rather than
include an assembly? I would prefer an assembly as this is how it
should be!

Thank you kindly for you help.

Alex
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message news:<Ot*************@tk2msftngp13.phx.gbl>...
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

Nov 17 '05 #3
Alex,

Yes, I think it's trying to use your windows login.

For the assembly I would just hard code the connection string in the
connection object. I believe that will solve your problem.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Alex" <al**@hotpop.com> wrote in message
news:c5**************************@posting.google.c om...
Morning Justin,

Thanks for you post. I'm using a specific user/pwd for the DB as
defined in the connection string. For completeness here it is:
<appSettings>
<add key="ConnectionString"
value="server=SomeServer;database=XXX;uid=XXX;pwd= yy;Trusted_Connection=yes" />
</appSettings>
I defined a specific DB user which the asp should use. Remember that
if I take the two files and put the code into the aspx page it works.
Simply cutting and pasting the two methods, and calling the method
directly (not creating the DB object) works.

You are thinking that when I split them accross two files it's trying
to use my WINDOWS username/pass to access the DB? I will look into it.
Where would this setting be?

Do you think it would be better to use a codebehind page rather than
include an assembly? I would prefer an assembly as this is how it
should be!

Thank you kindly for you help.

Alex
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message

news:<Ot*************@tk2msftngp13.phx.gbl>...
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

Nov 17 '05 #4
Hey,

I found what the problem was!
Ok, this is the set up I *had*. My project files resided on
\\server\myPersonalSpace

On the IIS box (different server) I had set up a Web Site poiting to
the folder on myPersonalSpace. I was invoking the file from DW which
has a site defined poiting to myPersonalSpace.

When I moved all the files from myPersonalSpace and dumped in the
folder in wwwroot, and re-defined the site in DW to point to this
folder. Everything worked.

It was the fact that the IIS server was running the files accross the
network that caused the problems. Now I have a nice set up with a
codebehind class, and a Database layer (dll in bin directory).

Works much better, but I do have another interesting problem.
marketerList.DataSource=data.GetList("spu_getMarke ters", "Marketer");
marketerList.DataBind();

GetList is your typical method that runs a stored proc. marketerList
is a dropdownlist containing names of marketers. The list is populated
first time it is loaded. When the page is posted back, my lists don't
get populated anymore.
Of course, it's not running the stored proc as I bypass it through

if(Page.IsPostBack)
{ //Do nothing }
else
{ GetList...}

I can't see why it's not preserving state between requests. I haven't
defined an "action" in the form tag. Any ideas?

Thanks a lot,
Alex

PS. I'll be sure to check out your code repository ;)
PSS. And i'll release what I write as well....assuming I get
permission....
http://www.alexpop.com -- The first ever website I wrote.
http://www.abridgegolf.com -- The last one I did.
Nov 17 '05 #5
Alex,

Great to hear that you solved it!

Repopulation not taking place is almost always due to viewstate not being
enabled (for the page, the placeholder a dynamic control is in, the dynamic
control itself, a regular control, a panel a regular control is in, etc.)

I suggest looking at all levels of viewstate you may have pertaining to this
particular control. It's probably disabled at some level.

About placing code in my repository: If you'd like to submit some to share
with others that would be great! Of course I'll give you credit for
anything included.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Alex" <al**@hotpop.com> wrote in message
news:c5**************************@posting.google.c om...
Hey,

I found what the problem was!
Ok, this is the set up I *had*. My project files resided on
\\server\myPersonalSpace

On the IIS box (different server) I had set up a Web Site poiting to
the folder on myPersonalSpace. I was invoking the file from DW which
has a site defined poiting to myPersonalSpace.

When I moved all the files from myPersonalSpace and dumped in the
folder in wwwroot, and re-defined the site in DW to point to this
folder. Everything worked.

It was the fact that the IIS server was running the files accross the
network that caused the problems. Now I have a nice set up with a
codebehind class, and a Database layer (dll in bin directory).

Works much better, but I do have another interesting problem.
marketerList.DataSource=data.GetList("spu_getMarke ters", "Marketer");
marketerList.DataBind();

GetList is your typical method that runs a stored proc. marketerList
is a dropdownlist containing names of marketers. The list is populated
first time it is loaded. When the page is posted back, my lists don't
get populated anymore.
Of course, it's not running the stored proc as I bypass it through

if(Page.IsPostBack)
{ //Do nothing }
else
{ GetList...}

I can't see why it's not preserving state between requests. I haven't
defined an "action" in the form tag. Any ideas?

Thanks a lot,
Alex

PS. I'll be sure to check out your code repository ;)
PSS. And i'll release what I write as well....assuming I get
permission....
http://www.alexpop.com -- The first ever website I wrote.
http://www.abridgegolf.com -- The last one I did.

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
1
by: ccr | last post by:
Please view in a text editor so that the columnar text lines up. I used Terminal 9pt font to compose this post and copied/pasted to my newsreader program. I am writing in the hope that one of...
1
by: ccr | last post by:
Reposted with a longer line length. Apologies if I did not cancel the 1st attempt before you got it. If necessary, please view in a text editor so the columnar text lines up. I used Terminal...
4
by: Roy | last post by:
Could someone point me in the right direction here? The current method of importing new data into our db goes something like this: 1.) txt files received via email 2.) employees clean data and...
0
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
6
by: Senthil | last post by:
Hi All We are having a VB application on SQL. But we need to collect information from persons who will be offline to verify data and insert new data. Generally they will be entering the data in...
3
by: mukeshsrivastav | last post by:
dear sir i want to move form excel to access. i have 5 excel file having same formats and fields.now i want to import all data in one access table. importing one file is easy .but importing and...
1
by: puremetal33 | last post by:
I have worked very little with Access and have hit a snag. My task right now is to import the data from a spreadsheet into an existing table in an Access database. I edited the .xls file so that...
2
by: Debbiedo | last post by:
I have a text file that I am importing into an Access table that was generatred from data exported from a Word file. Several (about 20-30) fields are from check boxes on the Word form. These fields...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.