Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 12th, 2004, 05:42 PM
Authorized User
 
Join Date: Jul 2003
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 13 Codebehind Connection

I've compartmentalized my code as directed by chapter 13 page 461. The only touble I'm having is I've had to change my connection string from "Dim connectionString As String = _
            ConfigurationSettings.AppSettings("ConnectionStrin g")" calling it from the web.config file. I now have to use the direct path "Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\BegASPNET\Wr"& _
     "oxUnited\Database\WroxUnited.mdb". Have I missed something or done something wrong.

ps: error was connection is not available.

Can the file with the vb extension with all the code in it see the connection from the web.config file?


Thanks!
Rich
 
Old September 13th, 2004, 08:04 AM
Authorized User
 
Join Date: Jul 2003
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the specific error I'm getting:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'ConfigurationSettings' is not declared.

Source Error:



Line 83: Function Dates() As System.Data.IDataReader
Line 84: Dim connectionString As String = _
Line 85: ConfigurationSettings.AppSettings("ConnectionStrin g")
Line 86: Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )
Line 87:


Source File: C:\begaspnet11\wroxunited\default.aspx.vb Line: 85

How do I fix it?

Thanks!
Rich

 
Old September 13th, 2004, 09:32 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Once you move your code out of a page class an into a helper class, you have moved it from executing in the scope of the page execution where ConfigurationSettings has context.

In the page you can do this:

foo = ConfigurationSettings.AppSettings.Item("asasasas")

Outside the page, in a helper class I think you can do this:

foo = System.Configuration.ConfigurationSettings.AppSett ings.Item("asasasas")

** HOWEVER! ** In a multi-tier design, you should avoid making a lower tier assume where to find connection data. The data is associated with the application, so provide the connection information to the underlying class from the consuming application. Perhaps my opinion on this is completely wrong and someone else can offer a better suggestion. In my mind, if you are storing the connection information in something application specific then the application should tell the data access class what the connection is. In this case the AppSettings node of the application's configuration file (web.config) contains the connection information.





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 13 - MVC omarosa BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 10 March 25th, 2009 12:00 AM
Chapter 13 bwoll BOOK: Beginning Access 2003 VBA 1 June 7th, 2007 03:57 PM
Chapter 13 ElMorenito BOOK: Beginning ASP 3.0 0 January 14th, 2005 02:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.