Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
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 3rd, 2004, 03:36 PM
Authorized User
 
Join Date: Jul 2003
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default The ConnectionString property has not been initial

Can't belive I've made it to chapter 10 without a post! I'm in chapter 10 page 340. Have tried to place the connection into the "web.config" file and am receving the following error. Can some one please help.
Code:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.

Source Error: 


Line 23:             dbCommand.Connection = dbConnection
Line 24: 
Line 25:             dbConnection.Open
Line 26:             Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Thanks!
Rich

 
Old September 3rd, 2004, 03:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

When you initialized the dbConnection, you didn't pass in a new connection string

dbConnection = New SQLConnection(ConfigurationSettings.AppSettings.Ge t("<key in config file>"))

Brian
 
Old September 4th, 2004, 01:42 PM
Authorized User
 
Join Date: Jul 2003
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I understand correctly. On the line where I Dim the dbconnection I need to point it to the connection I created in the web.config file. How would I do that?

Code:
Function GetTeams() As System.Data.IDataReader
            Dim connectionString As String = _
                ConfigurationSettings.AppSettings("connectionstring")
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)


Just to prove I don't post and give up. I've worked my self to this point.
Code:
Sub Page_Load()
        Teamlist.Datasource = getteams
        teamlist.databind()
    End Sub

        Function GetTeams() As System.Data.IDataReader
            Dim connectionString As String = _
                ConfigurationSettings.AppSettings("connectionstring")
            Dim dbConnection = ConfigurationSettings.AppSettings("connectionstring")

            Dim queryString As String = "SELECT [Teams].[TeamID], [Teams].[TeamName], [Teams].[Notes] FROM [Teams]"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection

            dbConnection.Open
            Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

            Return dataReader
        End Function


Now I get this:
Exception Details: System.NullReferenceException: Object variable or With block variable not set.

Source Error:


Line 21: dbCommand.Connection = dbConnection
Line 22:
Line 23: dbConnection.Open
Line 24: Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
Line 25:

Here is the contents of my web.config
Code:
<?xml version="1.0" encoding="UTF-8" ?>

<configuration>

    <!--

         The <appSettings> section is used to configure application-specific configuration
         settings.  These can be fetched from within apps by calling the
         "ConfigurationSettings.AppSettings(key)" method:

         <appSettings>
            <add key="connectionstring"
                value="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4;
                        Data Source=C:\begaspnet11\wroxunited\database\wroxunited.mdb"/>
         </appSettings>

    -->

    <system.web>

        <!--

            The <sessionState" section is used to configure session state for the application.
            It supports four modes: "Off", "InProc", "StateServer", and "SqlServer".  The
            later two modes enable session state to be stored off the web server machine -
            allowing failure redundancy and web farm session state scenarios.

            <sessionState mode="InProc"
                          stateConnectionString="tcpip=127.0.0.1:42424"
                          sqlConnectionString="data source=127.0.0.1;trusted_connection=true"
                          cookieless="false"
                          timeout="20" />

        -->

        <!--

            The <customErrors> section enables configuration of what to do if/when an
            unhandled error occurs during the execution of a request.  Specifically, it
            enables developers to configure html error pages to be displayed in place of
            a error stack trace:

            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
               <error statusCode="403" redirect="NoAccess.htm"/>
               <error statusCode="404" redirect="FileNotFound.htm"/>
            <customErrors>

        -->

        <!--

            The <authentication> section enables configuration of the security authentication
            mode used by ASP.NET to identify an incoming user.  It supports a "mode"
            attribute with four valid values: "Windows", "Forms", "Passport" and "None":

            The <forms> section is a sub-section of the <authentication> section,
            and supports configuring the authentication values used when Forms
            authentication is enabled above:

            <authentication mode="Windows">

                    <forms name=".ASPXAUTH"
                           loginUrl="login.aspx"
                           protection="Validation"
                           timeout="999999" />

             </authentication>

        -->


        <!--

            The <authorization> section enables developers/administrators to configure
            whether a user or role has access to a particular page or resource.  This is
            accomplished by adding "<allow>" and "<deny>" sub-tags beneath the <authorization>
            section - specifically detailing the users/roles allowed or denied access.

            Note: The "?" character indicates "anonymous" users (ie: non authenticated users).
            The "*" character indicates "all" users.

            <authorization>
               <allow users="joeuser" />
               <allow roles="Admins" />
               <deny users="*" />
            </authorization>

        -->

    </system.web>

</configuration>
 
Old September 4th, 2004, 09:16 PM
Authorized User
 
Join Date: Jul 2003
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please help. I finally decided just to use the downloaded code and I got this:

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.

Source Error:


Line 23: dbCommand.Connection = dbConnection
Line 24:
Line 25: dbConnection.Open
Line 26: Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
Line 27:


Source File: C:\begasnet11\wroxunited\teams.aspx Line: 25

Stack Trace:


[InvalidOperationException: The ConnectionString property has not been initialized.]
   System.Data.OleDb.OleDbConnection.Open() +203
   ASP.teams_aspx.GetTeams() in C:\begasnet11\wroxunited\teams.aspx:25
   ASP.teams_aspx.Page_Load() in C:\begasnet11\wroxunited\teams.aspx:9
   System.Web.Util.ArglessEventHandlerDelegateProxy.C allback(Object sender, EventArgs e) +10
   System.Web.UI.Control.OnLoad(EventArgs e) +55
   System.Web.UI.Control.LoadRecursive() +27
   System.Web.UI.Page.ProcessRequestMain() +731




 
Old September 6th, 2004, 06:02 PM
Authorized User
 
Join Date: Jul 2003
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm using webmatrix to do this. Do I need to turn the folder into a virtual directory to access the web.config file?

 
Old September 6th, 2004, 07:18 PM
Authorized User
 
Join Date: Jul 2003
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would'nt fee so dumb if I didn't read in this forum that some one else did the same thing (about 15 hours ago). OK here it is. The <appsettings> in the webconfig file was commented out. I removed the comment tags and bang.

Thanks everyone!!

 
Old March 17th, 2006, 11:24 PM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jasonld
Default

I have the exact same issue, but my <appSettings> node is not commented out. What may be the issue? Using WindowsXP Pro. Web.config looks like this-

<?xml version="1.0" encoding="iso-8859-1"?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwroot\CCCApplication1\ds\WroxU nited.mdb;" />
</appSettings>
    <system.web>
<compilation debug="true"/>
        <customErrors mode="Off"/>
        <identity impersonate="true" />
    </system.web>
</configuration>


Jason

http://www.benchmade.com
http://www.nraknives.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
The ConnectionString property has not been initial libbydoo ASP.NET 1.0 and 1.1 Basics 6 November 22nd, 2006 10:11 PM
the ConnectionString Property... coolb C# 3 September 26th, 2006 02:05 AM
The ConnectionString property...! rajesh0363 All Other Wrox Books 2 July 26th, 2005 01:55 PM
Re-Initial variable to zero akibaMaila VB.NET 2002/2003 Basics 3 July 12th, 2005 01:41 PM
Initial Apache setup fahrionm BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 June 7th, 2004 03:02 PM





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