p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   Web.Config..Working or Not Working (http://p2p.wrox.com/showthread.php?t=47906)

peace95 September 15th, 2006 08:13 PM

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>:
  <add key="NWind"
 value="server=(local); database=northwind4; integrated security=true;"/>
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.

dparsons September 18th, 2006 06:53 AM

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:

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

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.

All times are GMT -4. The time now is 01:08 AM.

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