Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 15th, 2006, 08:13 PM
Friend of Wrox
Points: 793, Level: 10
Points: 793, Level: 10 Points: 793, Level: 10 Points: 793, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default Web.Config..Working or Not Working

I am trying to use the web.config index property specifying the Connection String of an SQL db files. According to the documentation, u add the following code to web.config-
Lines inserted after </system.web> and before </configuration>:
<appSettings>
  <add key="NWind"
 value="server=(local); database=northwind4; integrated security=true;"/>
</appSettings>
</configuration>
In my .aspx program, Datareader, inserted after Sub Page_Load statement add the following:

Dim strConnection As String = Configuration.AppSettings("NWind")

Running the program generates the error: The Connection String property has not been initialized, with the Connection.Open() highlighted. This indicates to me, the .aspx program is not finding the SQL files Connection string in web.config.

I also tried the GetConfig("appSettings") prior to Dim strConnection stastement above.

I also tried:
Dim objConnection As New SqlConnection(ConfigurationSettings.AppSettings("N Wind"))

I am still getting the Connection string property has not been initialized.

My web.config file is located in the following directory:
C:\Inetpub\wwwrootAlso in my IIS Default WebSite folder.

I have a project that could use this function, so any help would be appreciated.

Thanks in advance.
__________________
Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.
 
Old September 18th, 2006, 06:53 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Is your web.config in the root directory of your application?

Have you tried just writing the value to the screen as opposed to actually trying to use it? (e.g. Response.Write(ConfigurationSettings.AppSettings("[keyname]"))

I store all of my database connection strings in the web.config file and do something like this:

web.config:
<appSettings>
<add key="Clients" value="workstation id=PC;user ID=Username;password=Password;data source=Server;persist security info=True;initial catalog=Database"/>
</appSettings>

In code:

sqlConn = New SqlConnection
sqlConn.ConnectionString = ConfigurationSettings.AppSettings("Clients")

And this works fine.

--Stole this from a moderator

I will only tell you how to do it, not do it for you.

Unless, of course, you want to hire me to do work for you.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Logins stopped working after adding to web.config troyb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 September 2nd, 2008 03:34 PM
Web service not working properly in IIS Abhinavnaresh ASP.NET 2.0 Professional 1 April 10th, 2008 08:53 AM
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM





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