Help with ASP.NET DataGrid problem

T

thebison

Hi,

As a relative newbie to SQL Server/ASP.NET I'm hoping someone here
can help with my problem. I'm developing a timesheet application in
ASP.NET C# using Visual Studio 2003 with a database built in MSDE.
One of my forms needs to return a simple list of resources from my
database. I have followed the guide on the MSDN libraries, but for
some reason I continuously get the same error message.

What I've done so far is Create the database, tables, and populate
with some sample data using using Server Explorer in Visual Studio. I
have
connected to the database (using integrated security) and I am
trying to get the contents of the Resource table to appear on my
form. I have then created a DataAdapter (tested the connection, set
the SQL as a simple SELECT * from Resource, etc), which also generates
an sqlConnection for me. To test this I have previewed the generated
data, and it returns what I want, so I
have chosen to generate a DataSet of this. I am then trying to get
this data into a simple DataGrid. On the properties of the DataGrid
I have changed the DataSource to point at my Dataset. As I
understand it, I then have to add the following to my Page Load
section of my code.

sqlConnection1.Open();
this.sqlDataAdapter1.Fill(this.dsResource);
DataGrid1.DataBind();
sqlConnection1.Close();

The form builds fine, but when I browse to the particular form I get
the following error for the sqlConnection1.Open(); line. If I remove
this line the error simply moves to the line below.

Exception Details: System.Data.SqlClient.SqlException: Cannot open
database requested in login 'SCMS'. Login fails. Login failed for
user 'AL-NOTEPAD\ASPNET'.

To me this is an error with my connection string. My database
instance is actually 'AL-NOTEPAD\VSDOTNET'. However the properties
for sqlConnection1 are pointing to the correct datasource. I do not
know why the application is looking for user 'AL-NOTEPAD\ASPNET'. It
does not exist, to my knowledge. Do I need to grant access to this
user? If so, how would I do it?

Any help with this would be greatly appreciated, as I get the same
error with my code for forms-based login...


Thanks in advance..
 
A

Alec MacLean

Exception Details: System.Data.SqlClient.SqlException: Cannot open
database requested in login 'SCMS'. Login fails. Login failed for
user 'AL-NOTEPAD\ASPNET'. ....

To me this is an error with my connection string. My database
instance is actually 'AL-NOTEPAD\VSDOTNET'. However the properties
for sqlConnection1 are pointing to the correct datasource. I do not
know why the application is looking for user 'AL-NOTEPAD\ASPNET'. It
does not exist, to my knowledge. Do I need to grant access to this
user? If so, how would I do it?


The ASPNET user is a local user created when you installed VS. By default
the web apps are using this as the logon user for browser sessions.

I'm not entirely sure why your integrated (SSPI) setting is being ignored.

You can override this for your data connection by editing the connection
string to include a SQL user. This user needs to have sproc execute
permissions, which you can set in SQL Enterprise Manager. You may want to
consider adding a Role, setting the sproc exec permissions for the role,
then having the SQL user account be a member of the role.

It may also be useful to know that the connection string can be stored in
your web.config, using a custom configuration key. This would prevent you
having to recompile the app if the SQL user account password ever changes.
If necessary, you can hash the connection string to make it more secure.
sqlConnection1.Open();
this.sqlDataAdapter1.Fill(this.dsResource);
DataGrid1.DataBind();
sqlConnection1.Close();

You may want to add
DataGrid1.Datasource = sqlDataAdapter1
before your bind statement if you haven't already done this using the
designer properties.

Hope this helps.

Al
 
T

thebison

Hi,


Thanks for all the help, I've sorted the problem in the short term by
downloading an MSDE alternative to Enterprise Manager
(http://www.asql.biz/DbaMgr.shtm) and assigned the relevant access to
the ASPNET user account. The DataGrid now works.


Thanks again

Alex
 

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

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top