Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 8th, 2011, 04:45 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Default Configuration Error in Web.config

I ported my site over to a 2008 R2 server using SQL Express 2008. When I run it from http://localhost, I get the login screen. When I enter the login info and click Ok, I get a Configuration Error, with the second "add name" line highlighted in red. The first one appears to run ok. I'm basing the syntax of this line from Appendix B, page 770. The aspnetdb.mdf is still in the site's App_Data folder, but was attached to the SQLEXPRESS database from there, and then given rights to the NET4 user.

Note that the error also says, "Parser Error Message: The entry 'LocalSqlServer' has already been added." I checked the Web.config file, and the word "LocalSqlServer" is only used once.

Here are the two lines - the second one is giving the error (I tried changing the second to completely match the first to the right of the inital catalog, but that didn't get rid of the error):

Code:
<configuration>
  <connectionStrings>
    <add name="BCConnectionString" connectionString="data source=IT-TEST2\SQLEXPRESS;initial catalog=BC; integrated security=SSPI;persist security info=False; Trusted_Connection=Yes" providerName="System.Data.SqlClient" />
  
    <add name="LocalSqlServer" connectionString="data source=IT-TEST2\SQLEXPRESS;Initial Catalog=aspnetdb;Trusted_Connection=True" providerName="System.Data.SqlClient" />
</connectionStrings>
It worked on the production server with the aspnetdb file unattached to SQL. Here is the line from that Web.config file:

Code:
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
      providerName="System.Data.SqlClient" />

Last edited by BobRoberts; November 8th, 2011 at 05:00 PM..
Reply With Quote
  #2 (permalink)  
Old November 8th, 2011, 04:50 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

It would help if you included the actual error...

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!
Reply With Quote
  #3 (permalink)  
Old November 8th, 2011, 05:01 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Sorry - it's:

Parser Error Message: The entry 'LocalSqlServer' has already been added. I checked the Web.config file, and the word LocalSqlServer is only used once.
Reply With Quote
  #4 (permalink)  
Old November 8th, 2011, 05:10 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

It's because it's already defined at the machine level in machine.config.

Add a <clear /> element at the top of the connectionStrings node to get rid of that one.

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!
Reply With Quote
  #5 (permalink)  
Old November 8th, 2011, 05:33 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The error now:
Parser Error Message: The connection name 'ApplicationServices' was not found in the applications configuration or the connection string is empty.


Now it seems to be balking at the ConnectionStringName = "ApplicationServices" in the provider sections toward the bottom. I assume I should change that ConnectionStringName to LocalSqlServer, though that isn't mentioned in this section of the book. Something similar is talked about on page 774.
Reply With Quote
  #6 (permalink)  
Old November 8th, 2011, 05:43 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I did that and am getting:

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "aspnetdb" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.

I just checked and the user IIS AppPool\ASP.NET v4.0 has all Role Members checked that start with "aspnet".
Reply With Quote
  #7 (permalink)  
Old November 8th, 2011, 05:56 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Did you assign role membership or schema ownership?
__________________
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!
Reply With Quote
  #8 (permalink)  
Old November 8th, 2011, 06:07 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Role membership - didn't do anything with the schema, because it wasn't in your instructions. I just tried checking dbowner, and also changing the connection string to login as sa, but the login failure persists.
Reply With Quote
  #9 (permalink)  
Old November 8th, 2011, 06:27 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Tried to get it to work the old way, with the aspnetdb in the App_Data folder without being attached to the SQL server, using the same connection string as on the development server, but getting:

Exception Details: System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to a failure in impersonating the client. The connection will be closed.


The only thing left to try is what's described on page 771, "Configuring Your Database for the Application Services".
Reply With Quote
  #10 (permalink)  
Old November 8th, 2011, 07:05 PM
Registered User
Points: 87, Level: 1
Points: 87, Level: 1 Points: 87, Level: 1 Points: 87, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
Exclamation It Worked!

I tried one more thing before going the route of configuring my database for the application services - AND IT WORKED! I reasoned there was something fundamentally wrong with the security on the aspnetdb database as it was created. So, I detached it and deleted the mdf. I then went back to my development PC and attached that database to my SQL instance, and then I backed it up. I copied the backup file to the production server, into the SQL data directory, and then I went into the SQL on the production server and restored it - effectively creating it. And, maybe important, I made sure I was logged on as sa when I did these things. I got a fresh Web.config from the development PC, and modified it exactly as 770 specifies. And that seemed to do the trick - it might have been the combination of restoring instead of attaching, and making sure it was done while logged in as "sa". Thanks Imar - I want to tell you you've written an extraordinary book that's clear and detailed without being confusing.
Reply With Quote
The Following User Says Thank You to BobRoberts For This Useful Post:
Imar (November 9th, 2011)
Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fix for Web.config Error in ...\Chapter01\LINQforBinding Web Sites rogerj BOOK: Professional ADO.NET 3.5 with LINQ and the Entity Framework ISBN: 978-0-470-22988-0 0 February 18th, 2009 01:59 PM
web.config error koco ASP.NET 2.0 Basics 1 February 16th, 2007 12:04 PM
Web Service Configuration Error DudeBori82 ASP.NET 2.0 Professional 0 November 13th, 2006 01:31 PM
error at web.config aynajus BOOK: ASP.NET Website Programming Problem-Design-Solution 2 August 16th, 2006 03:24 AM
Web.Config xmlns for <configuration> mhardiman BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 July 9th, 2006 11:08 AM



All times are GMT -4. The time now is 10:58 AM.


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