Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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 April 29th, 2006, 03:43 PM
Registered User
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default ConnectionString not initialized

I'm writing some code for the first time using Asp.net 2.0 to get a datareader to pass some info to labels on my form.

The connectionstring I am using works with everything else, but not with this example. I keep getting the "System.InvalidOperationException: The ConnectionString property has not been initialized" message. What's wrong with my code?:

Dim strID As String
  strID = Me.ddl_name.SelectedValue

Dim sqlConn As SqlConnection = New SqlConnection(ConfigurationManager.AppSettings.Get ("connectionString"))
Dim cmdSelectRider As SqlCommand
 cmdSelectRider = New SqlCommand("SELECT * from members where [ID]='" & strID.ToString & "'", sqlConn)

Dim drRider As SqlDataReader
 drRider = cmdSelectRider.ExecuteReader()
        While drRider.Read
            lbl_first_name.Text = drRider("first_name")
            lbl_last_name.Text = drRider("last_name")
        End While

Old April 30th, 2006, 03:22 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

Did you store the connectionstring in the <appSettings> node or in the <connectionStrings> node in the web.config file?

Normally, you would use the connectionStrings section, but your code is accessing the appSettings:

ConfigurationManager.AppSettings.Get("connectionSt ring")

should be something like:

ConfigurationManager.ConnectionStrings("connection String").ConnectionString

Hope this helps,

Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Techno Rave Entrance by Blade (From the album: Blade Soundtrack) What's This?
Old April 30th, 2006, 06:18 AM
Registered User
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Right you are. Works well! I finally figured out that that was what it was, but just couldn't get the syntax right. thanks for the help!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection property has not been initialized sasi.vempalli ASP.NET 1.0 and 1.1 Basics 0 September 19th, 2006 03:03 AM
Connection Property:Has not been initialized louie001 ASP.NET 1.0 and 1.1 Basics 1 October 17th, 2005 11:46 PM
connection not initialized jazzcatone ASP.NET 1.x and 2.0 Application Design 1 July 29th, 2005 01:02 PM
Connection has not initialized Properly ERROR!!!! ramana123 ASP.NET 1.0 and 1.1 Basics 0 July 7th, 2005 01:01 AM
which you have not initialized Gurpreetb78 Classic ASP Components 0 January 27th, 2005 03:42 PM

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