Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 29th, 2010, 09:47 AM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Default Problem

Hi

i am sorry to be persistent with posting here but i believe this should be the right place to post for the asp.net 3.5 enterprise application development book to get some help.

I would be grateful if Vince Varallo the author of the book or somebody who is expert could take a bit of his time to help me.

I find wrox books great because they are full of practical examples and i want to become a professional developer.

I have followed the book step by step until chapter 4 and there are no errors when i compile.

However when i run the application i get an exception.

This is the exception that i get.

System.Reflection.TargetInvocationException

i hope i will get an answer to solve this.

i have spent the entire morning checking that sql server is being set up properly. The server is running, TCP/IP port is open, allow remote connection enabled.

When i run the website from IIS which tries to open the Administration/Users.aspx page i get the following error:

Object reference not set to an instance of an object
Line 17: return ConfigurationManager.ConnectionStrings[EAD_CONNSTRING_KEY].ConnectionString;

That line is in the DBHelper class.

I am using windows server 2008 R2 with sql server 2008 R2.

i think is a small mistake but i can not figure out how to solve it and is becoming really frustrating.

Please help.

kind regards

MattHoff
  #2 (permalink)  
Old July 29th, 2010, 01:28 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,
Quote:
Line 17: return ConfigurationManager.ConnectionStrings[EAD_CONNSTRING_KEY].ConnectionString;
This seems to imply that EAD_CONNSTRING_KEY is empty, or contains a value that does not have a matching connection string in the web.config file.

What do you see when you look in the web.config in the <connectionStrings /> node? Do you see connections listed there? And what happens when you debug and look at the value of the EAD_CONNSTRING_KEY variable?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old July 29th, 2010, 02:40 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Default response to:Imar

Hi Imar

thank you for reply.

in the web.config file i have the following line in the <connectionStrings> node:

Code:
<connectionStrings>
<add name="EAD_ConnString" connectionString="Data Source=WIN-4ZJRZD08QT7\SQLEXPRESS;Initial Catalog=EAD; Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
This is the DBHelper class:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;


namespace A1.Data_Access_layer.Framework
{
    public class DBHelper
    {
        private const string EAD_CONNSTRING_KEY = "EAD_ConnString";

        public static string GetEADConnectionString()
        {
            return ConfigurationManager.ConnectionStrings[EAD_CONNSTRING_KEY].ConnectionString;
        }

    }
}
So the value of EAD_CONNSTRING_KEY matches the value of that <connectionStrings> node.

I have an administration Folder in the user interface that contains three pages: Administration.aspx, Users.aspx, and User.aspx.

When i debug with the Users.aspx as start up option i get
Code:
System.Reflection.TargetInvocationException
with the following line highlighted in yellow:
Code:
objectType.InvokeMember(LoadMethodName, BindingFlags.InvokeMethod, null, listObject, _methodParameters.ToArray());
When i debug either with the Administration.aspx or User.aspx as start up option i get the following:

Cannot open database "EAD" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE' with the following line part of EAD_DataContext.designer.cs highlighted in red

Code:
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.ENTMenuItemSelectAll")]
public ISingleResult<ENTMenuItem> ENTMenuItemSelectAll()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
	return ((ISingleResult<ENTMenuItem>)(result.ReturnValue));
		}
The IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))); line is highlighted in red.

the pool identity in IIS is set to Network Service and the Load User profile is set to False.

Hope this helps.

Thank you

Regards

MattHoff

Last edited by MattHoff; July 29th, 2010 at 02:48 PM.. Reason: Missing text
  #4 (permalink)  
Old July 29th, 2010, 02:54 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
Cannot open database "EAD" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE' with the following line part of EAD_DataContext.designer.cs highlighted in red
This seems to indicate you have a problem with SQL Security. Maybe this article helps: http://imar.spaanjaars.com/395/confi...ql-server-2005

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
MattHoff (July 29th, 2010)
  #5 (permalink)  
Old July 29th, 2010, 07:03 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Imar

You are a legend.

thank you so much for your support i really appreciate it.

i have read your article and i have successfully solved the problem that has afflicted me for 2 long days.

Have you got some suggestion in terms of books that i should read to help me to learn all this sort of configuration settings?

i am thinking of getting your ASP.NET 2.0 Instant results. 12 applications sound good to me.
maybe i could find a way to wrap them together and create a single bigger application.
At the same time i am wondering if it would be possible to migrate to .NET 3.5 with a bit of work.

I am using windows server 2008 R2 as i am a student i got it for free, VS2010 and sql server 2008 enterprise. I have installed the enterprise library 5.0 as well.

chapter 5 of this book treats exception handling but some of the assemblies used in the web.config file are old or not compatible with VS2010. I have managed to replace the Microsoft.ReportViewer.WebForms, and Microsoft.ReportViewer.Common by adding .NET references but when it comes to CrystalDecisions i can not find any reference.

Do you know why? is there anything that i need to install?

kind regards

MattHoff
  #6 (permalink)  
Old July 30th, 2010, 09:23 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
i have read your article and i have successfully solved the problem that has afflicted me for 2 long days.
Good to hear that.

Quote:
i am thinking of getting your ASP.NET 2.0 Instant results. 12 applications sound good to me.
maybe i could find a way to wrap them together and create a single bigger application.
At the same time i am wondering if it would be possible to migrate to .NET 3.5 with a bit of work.
I think most, if not all, will run directly under ,NET 3.5 and 4.0. Obviously, it doesn't make use of new technologies and other improvements, but you could gradually upgrade them. Not sure if wrapping them together is a good idea as most tools aren't very related to each other.

Quote:
Have you got some suggestion in terms of books that i should read to help me to learn all this sort of configuration settings?
It depends on what you're referring to exactly. My book Beginning ASP.NET 4 in C# and VB shows a lot of this stuff (the article I posted is rewritten as an appendix). Check out my signature for links to the book.

Quote:
Do you know why? is there anything that i need to install?
Not sure exactly. Try running the VS 2010 setup and see if you have components that are currently not installed.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #7 (permalink)  
Old August 18th, 2010, 06:21 AM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Default Membership information problem

Hi Imar

Hope you can help me and that i don't disturb you. The author of the book does not seems to be around much this forum and is not of much help unfortunately.

I have a problem in mapping the WindowsAccountName field of the UserAccount table to the CurrentUser label placed at the upper right of the window.

I have disabled Anonymous Authentication and enabled ASP.NET impersonation and Windows Authentication in the IIS manager. I have changed the System Administrator record WindowsAccountName field in the UserAccount table with machinename/myname and also FirstName and LastName fields.

In the web.config i have modified the <connectionString> and put Integrated Security equals to True instead of using the original fields of the Author of the book that were in place. There were UserID = V2Application; Password = wrox; I have noticed that V2Application is like a role that can be given permissions in SQLServe management Studio when creating new Users. Still is not clear for me what actually V2Application does but i presume has got something to do with mapping the accounts.

When i run the application the current user appears to be the account of my machine which i access with as Administrator, therefore there is no side menu on the screen when i click on the Administration Tab.

Also there is a strange thing happening - to run the application without errors i must take off the virtual method CheckCapabilities in the BasePage otherwise if i don't take it off the application returns an error on the line

Code:
 switch (CurrentUser.GetCapabilityAccess(capability.ID, Globals.GetRoles(this.Cache)))
I presume i get this error because the account of the machine is not associated with the Useraccount table or because the server can not map this account with the capabilities associated with this user.

Is been almost a week now to try to solve this issue but unfortunately have not succeed.

Regards

Matt
  #8 (permalink)  
Old August 18th, 2010, 06:35 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I have disabled Anonymous Authentication and enabled ASP.NET impersonation
When you enable ASP.NET impersonation, the web site process runs under the user's account. That is, the user that browses your web site. is that really what you want? It also explains this:
Quote:
When i run the application the current user appears to be the account of my machine which i access with as Administrator
In other words, you log in to Windows using the Administrator account. This means the browser runs under that account. Because of impersonation, the requests made by you run under that account as well. So, database access (when using Integrated Security) runs as Administrator as well.

Maybe that explains things?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #9 (permalink)  
Old August 18th, 2010, 07:04 AM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Default

HTML Code:
When you enable ASP.NET impersonation, the web site process runs under the user's account. That is, the user that browses your web site. is that really what you want?
I don't want that - what i want are the users defined in the tables that have roles and capabilities associated with the use of the relational schema and the relationships.

HTML Code:
In other words, you log in to Windows using the Administrator account. This means the browser runs under that account. Because of impersonation, the requests made by you run under that account as well. So, database access (when using Integrated Security) runs as Administrator as well. Maybe that explains things?
It does explain things.
However i don't understands what changes i need to make and where to connect the user accounts in the database to the server so that the users are displayed correctly along with their roles so they can view their menus and pages accordingly.

I have tried to create users in the sql server management studio but that does not make sense because the users are already created in the UserAccoun table and connected to the Roles table. I have tried the ASP.NET configuration but there as well i don't need to create users and roles because they already exist in the database.

Also there is no password field in any of the tables so i don't understand how the author originally had the connection string as follow and accessed the website with a WindowsAccountName placed in the database:

Code:
<add name="LocalSqlServer" connectionString="Data Source=VARALLO1;Initial Catalog=PTOPersonalization;User ID=V2Application;Password=wrox" providerName=""/>
Code:
<add name="HRPaidTimeOffConnString" connectionString="Data Source=VARALLO1;Initial Catalog=HRPaidTimeOff;User ID=V2Application;Password=wrox" providerName=""/>
Here V2Application seems to be a general userID created using the database script and it appears in the database Role membership list when you try to create a new user using SQL Server Management studio.

Regards

Matt
  #10 (permalink)  
Old August 18th, 2010, 07:15 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I don't know enough of this application to say something useful about this.

But you can't use a user account defined in a table to access the database. In order to determine which user is listed in a table, you need to access the database first.

Typically, the data access runs under a specific account and the application then determines who can access what data.

The user ID in the connection string is a SQL Server user, defined in SQL Server with access to your database. It's not related to any of the records in one of your tables.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 05:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.