 |
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 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
|
|
|
|
|

February 15th, 2005, 03:05 PM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

February 15th, 2005, 03:43 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Could you post the code? I don't have the book.
|
|

February 15th, 2005, 04:06 PM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

February 16th, 2005, 02:35 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

February 16th, 2005, 03:29 PM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

February 17th, 2005, 01:50 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

February 17th, 2005, 02:28 PM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

May 3rd, 2005, 04:58 PM
|
|
Registered User
|
|
Join Date: May 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 2nd, 2006, 07:20 PM
|
|
Registered User
|
|
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
check the web.config file, you might comment out the <appSettings>
good luck
|
|

March 16th, 2007, 04:43 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |