Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > BOOK: Beginning ASP.NET 1.1
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 15th, 2005, 03:05 PM
GKL GKL is offline
Registered User
 
Join Date: Feb 2005
Location: Miami, FL, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question about Teams.aspx in Chapter 10

Hello everyone. This is my first time writing to the forum, and I'm new to ASP.NET .

Right now, I'm in chapter 10, working on the Teams.aspx file. I followed the directions for the example but I am receiving an error that states "The ConnectionString property has not been initialized."

I already checked the errata page to see if there was any errors, but none was noted. Thanks in advance for any input you could provide.
Reply With Quote
  #2 (permalink)  
Old February 15th, 2005, 03:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Could you post the code? I don't have the book.
Reply With Quote
  #3 (permalink)  
Old February 15th, 2005, 04:06 PM
GKL GKL is offline
Registered User
 
Join Date: Feb 2005
Location: Miami, FL, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the code for Teams.aspx. The GetTeams() function was created in the Web Matrix Code Wizard.

<%@ Page Language="C#" %>
<script runat="server">

    void Page_Load(){

        TeamList.DataSource = GetTeams();
        TeamList.DataBind();

    }

    System.Data.IDataReader GetTeams() {
            string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];
            System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString );

            string queryString = "SELECT [Teams].* FROM [Teams]";
            System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
            dbCommand.CommandText = queryString;
            dbCommand.Connection = dbConnection;

            dbConnection.Open();
            System.Data.IDataReader dataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection);

            return dataReader;
        }

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
        </p>
        <h1>Wrox United
        </h1>
        <p>
        </p>
        <p>
        </p>
        <h2>Teams
        </h2>
        <p>
            <asp:DataList id="TeamList" runat="server">
                <ItemTemplate>
                    <asp:linkbutton text= '<%# DataBinder.Eval(Container.DataItem, "TeamName") %>' CommandArgument= '<%# DataBinder.Eval(Container.DataItem, "TeamID") %>' id= "TeamNameLink" style= "color:darkred" runat="server" />
                    <br />
                </ItemTemplate>
                <SeparatorTemplate>
                    <br />

                </SeparatorTemplate>
            </asp:DataList>
        </p>
    </form>
</body>
</html>

Also, I'm including the code for the web.config file the book asked me to make:

<?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\WroxUnit ed.mdb"/>
         </appSettings>

    -->

    <system.web>


Hope this clears things up. Thanks again for you help.
Reply With Quote
  #4 (permalink)  
Old February 16th, 2005, 02:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Are you sure this is returning a value? Try:

string connectionString = ConfigurationSettings.AppSettings.Get["ConnectionString"];

Try and make sure that the connection is being returned, by writing it out.

Brian
Reply With Quote
  #5 (permalink)  
Old February 16th, 2005, 03:29 PM
GKL GKL is offline
Registered User
 
Join Date: Feb 2005
Location: Miami, FL, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian! I tried your suggestion, but I got a Compilation Error instead.

Compiler Error Message:CS0654:Method'System.Collections.Specializ ed.NameValueCollection.Get(string)' referenced withour parentheses

So then I tried:

string connectionString = ConfigurationSettings.AppSettings.Get("ConnectionS tring"); I got "The ConnectionString property has not been initialized", which is the same error I started out with.

One thing of note, I think I should let you know: I made another .aspx page called Teams2.aspx just like this but instead of GetTeams being a DataReader function, I made it a DataSet function and set the connectionString to "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services =-4; Data Source=C:\\BegASPNET11\\Ch10\\WroxUnited.mdb" and it seemed to work fine.

So then I tried the "direct" connectionString on the original Teams.aspx. It seemed to work fine, at least I did not get an error, and page looked like the end result in the book. I even deleted the web.config file and I was able to load Teams.aspx without any problems.

This is fine and good, but now I'm really confused, because according to the book, and I quote, "However, the Web Matrix wizards don't allow you do specify a centralized data connection string, so we added a line to the default web.config file created for this exercise..." Then it reiterates the code given.

This contradicts the fact that if I left the IDataReader alone without changing the connectionString, and not creating the web.config file it seems to work fine.

Now I don't even know why the web.config file is necessary. I hope I'm not making this more complicated than it should be, but came into this book with no knowledge of XML, or any indication from the authors that I needed to know XML.

Thanks again for your input. I hope I did not make you feel like you stepped on a landmine.
Reply With Quote
  #6 (permalink)  
Old February 17th, 2005, 01:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Seems to me that it isn't finding the connection string... That's right, get should have (). Try Response.Write() the connection, to make sure something is coming out.

Brian
Reply With Quote
  #7 (permalink)  
Old February 17th, 2005, 02:28 PM
GKL GKL is offline
Registered User
 
Join Date: Feb 2005
Location: Miami, FL, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sorry, could you please rephrase that? At first I thought you meant to include a Response.Write() function in, but then it hit me that Response.Write() won't show anything if the page has an error, so I'm not sure exactly what you're suggesting.
Reply With Quote
  #8 (permalink)  
Old May 3rd, 2005, 04:58 PM
Registered User
 
Join Date: May 2005
Location: cs, co, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am Having the exact same prob. i have even compared my pages to the samples and there exactly the same...( and the sample run,, but not MY code) i cant figure this problem out.
Reply With Quote
  #9 (permalink)  
Old August 2nd, 2006, 07:20 PM
sjn sjn is offline
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

check the web.config file, you might comment out the <appSettings>
good luck

Reply With Quote
  #10 (permalink)  
Old March 16th, 2007, 04:43 AM
Registered User
 
Join Date: Mar 2007
Location: New Delhi, New Delhi, India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Guria
Default

Hello everybody,
Can anyone help me out? I am in ch10 and creating teams.aspx in visual studio.net but I'm getting the error "The type or namespace name ConfiguartionSettings could not be found(are u missing a using directive or an assembly reference)"
The code is as follws for Teams.aspx.cs:-
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration.Assemblies;

namespace wroxunited
{
    /// <summary>
    /// Summary description for Teams.
    /// </summary>
    public class Teams : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataList TeamList;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            TeamList.DataSource=GetTeams();
            TeamList.DataBind();
        }
        System.Data.IDataReader GetTeams()
        {
            String conString=ConfigurationSettings.AppSettings["ConnectString"];
            System.Data.IDbConnection dbconn=new System.Data.OleDb.OleDbConnection(conString);
            String qryString="SELECT [Teams].[TeamID],[Teams].[TeamName],[Teams].[Notes] from [Teams]";
            System.Data.IDbCommand dbcmd=new System.Data.OleDb.OleDbCommand();
            dbcmd.CommandText=qryString;
            dbcmd.Connection=dbconn;
            dbconn.Open();
            System.Data.IDataReader dataReader=dbcmd.ExecuteReader(System.Data.Command Behavior.CloseConnection);
         return dataReader;


        }
and code for Teams.aspx is as follws:-
<%@ Page language="c#" Codebehind="Teams.aspx.cs" AutoEventWireup="false" Inherits="wroxunited.Teams" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>Teams</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Teams" method="post" runat="server">
            <h1>Wrox United</h1>
            <h2>Teams</h2>
            <p>
                <TABLE id="Table1" style="Z-INDEX: 101; LEFT: 20px; WIDTH: 396px; POSITION: absolute; TOP: 114px; HEIGHT: 70px" cellSpacing="0" cellPadding="0" width="396" border="0">
                    <TR>
                        <TD style="WIDTH: 186px; HEIGHT: 37px">
                            <asp:DataList id="TeamList" runat="server" Width="354px">
                                <ItemTemplate>
                                    <asp:LinkButton text='<%# DataBinder.Eval(Container.DataItem, "TeamName") %>' CommandArgument='<%# DataBinder.Eval(Container.DataItem, "TeamID") %>' ID="TeamNameLink" style="color:darkred" Runat=server>
                                    </asp:LinkButton>
                                    <br>
                                    <asp:Label text='<%# DataBinder.Eval(Container.DataItem, "Notes") %>' ID="teamnotes" Runat=server>
                                    </asp:Label>
                                </ItemTemplate>
                                <SeparatorTemplate>
                                    <br>

                                </SeparatorTemplate>
                            </asp:DataList></TD>
                        <TD></TD>
                    </TR>
                </TABLE>
            </p>
        </form>
    </body>
</HTML>
and code for web.config file is as follws:-
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="ConnectString" value="Provider=Microsoft.Jet.OLEDB.4.0;Ole DB Services=-4;Data Source=D:\\Begaspnet\\WroxUnited\\Database\\WroxUn ited.mdb"></add>


    </appSettings>

  <system.web>
</system.web>

</configuration>



shraddha
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10 gogeo BOOK: Beginning Access 2003 VBA 1 January 22nd, 2006 09:41 AM
Another chapter 10 question. czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 4 April 3rd, 2005 09:12 PM
Question on chapter 10 - overriding RobMeade BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 4 August 12th, 2004 11:56 AM
Chapter 10 Navigator.aspx problem jason88 BOOK: Beginning ASP.NET 1.0 0 May 27th, 2004 03:54 AM



All times are GMT -4. The time now is 07:30 AM.


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