Newbie: problem posting

Discussion in 'ASP .Net' started by John Spiegel, Aug 25, 2003.

  1. John Spiegel

    John Spiegel Guest

    Hi All,

    I've got the following .aspx file with the then following .cs code. The
    page renders fine on first run, but once I click the submit, it just comes
    back with a cannot be displayed page indicating that the page is not
    available. Anyone see what probably obvious or stupid thing I'm missing?

    TIA,

    John

    Test.aspx:
    ========

    <%@ Page Language="C#" Src="Temp.cs" Inherits="dgrdAccountSort" %>
    <html>
    <head>
    </head>
    <body>
    <form runat="server">
    <asp:datagrid id="grdAccount" runat="server" Height="100%"
    Width="100%"></asp:datagrid>
    <input type="submit" value="Submit Query" runat="server" />
    </form>
    </body>
    </html>


    Temp.cs code:
    ==========
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.OleDb;

    public class dgrdAccountSort : Page
    {
    private string SortExpression;
    protected DataGrid grdAccount;

    protected void Page_Load(object Src, EventArgs e)
    {
    BindGridReader();
    }


    public void BindGridReader()
    {
    string SelectCommand = "SELECT * FROM AcctName";
    if (SortExpression != null)
    SelectCommand += " ORDER BY " + SortExpression;

    OleDbConnection conn = new OleDbConnection(@"Provider=vfpoledb.1;User
    Id=;Password=;Data
    Source=C:\temp\dotnet1.1\asp\essentials\samples\mytesting\IntelligentOffice"
    );
    OleDbCommand cmd = new OleDbCommand( SelectCommand, conn );

    conn.Open();
    IDataReader reader = cmd.ExecuteReader();
    grdAccount.DataSource = reader;
    grdAccount.DataBind();

    conn.Dispose();
    }
    }
    John Spiegel, Aug 25, 2003
    #1
    1. Advertising

  2. John,

    Instead of Connection.Dispose();

    Use Connection.Close(); and then Connection.Dispose() instead.

    Connection.Dispose() tells the .Net garbage collector that it's okay to
    dispose of an object when it gets around to it. It does not close the
    connection.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "John Spiegel" <> wrote in message
    news:...
    > Hi All,
    >
    > I've got the following .aspx file with the then following .cs code. The
    > page renders fine on first run, but once I click the submit, it just comes
    > back with a cannot be displayed page indicating that the page is not
    > available. Anyone see what probably obvious or stupid thing I'm missing?
    >
    > TIA,
    >
    > John
    >
    > Test.aspx:
    > ========
    >
    > <%@ Page Language="C#" Src="Temp.cs" Inherits="dgrdAccountSort" %>
    > <html>
    > <head>
    > </head>
    > <body>
    > <form runat="server">
    > <asp:datagrid id="grdAccount" runat="server" Height="100%"
    > Width="100%"></asp:datagrid>
    > <input type="submit" value="Submit Query" runat="server" />
    > </form>
    > </body>
    > </html>
    >
    >
    > Temp.cs code:
    > ==========
    > using System;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Data;
    > using System.Data.OleDb;
    >
    > public class dgrdAccountSort : Page
    > {
    > private string SortExpression;
    > protected DataGrid grdAccount;
    >
    > protected void Page_Load(object Src, EventArgs e)
    > {
    > BindGridReader();
    > }
    >
    >
    > public void BindGridReader()
    > {
    > string SelectCommand = "SELECT * FROM AcctName";
    > if (SortExpression != null)
    > SelectCommand += " ORDER BY " + SortExpression;
    >
    > OleDbConnection conn = new OleDbConnection(@"Provider=vfpoledb.1;User
    > Id=;Password=;Data
    >

    Source=C:\temp\dotnet1.1\asp\essentials\samples\mytesting\IntelligentOffice"
    > );
    > OleDbCommand cmd = new OleDbCommand( SelectCommand, conn );
    >
    > conn.Open();
    > IDataReader reader = cmd.ExecuteReader();
    > grdAccount.DataSource = reader;
    > grdAccount.DataBind();
    >
    > conn.Dispose();
    > }
    > }
    >
    >
    S. Justin Gengo, Aug 25, 2003
    #2
    1. Advertising

  3. John Spiegel

    Rick Spiewak Guest

    Just a thought - have you tried closing the connection by setting the
    commandbehavior of your command to do so after the Datareader is closed. And
    then close the datareader after binding?

    "John Spiegel" <> wrote in message
    news:...
    > Hi All,
    >
    > I've got the following .aspx file with the then following .cs code. The
    > page renders fine on first run, but once I click the submit, it just comes
    > back with a cannot be displayed page indicating that the page is not
    > available. Anyone see what probably obvious or stupid thing I'm missing?
    >
    > TIA,
    >
    > John
    >
    > Test.aspx:
    > ========
    >
    > <%@ Page Language="C#" Src="Temp.cs" Inherits="dgrdAccountSort" %>
    > <html>
    > <head>
    > </head>
    > <body>
    > <form runat="server">
    > <asp:datagrid id="grdAccount" runat="server" Height="100%"
    > Width="100%"></asp:datagrid>
    > <input type="submit" value="Submit Query" runat="server" />
    > </form>
    > </body>
    > </html>
    >
    >
    > Temp.cs code:
    > ==========
    > using System;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Data;
    > using System.Data.OleDb;
    >
    > public class dgrdAccountSort : Page
    > {
    > private string SortExpression;
    > protected DataGrid grdAccount;
    >
    > protected void Page_Load(object Src, EventArgs e)
    > {
    > BindGridReader();
    > }
    >
    >
    > public void BindGridReader()
    > {
    > string SelectCommand = "SELECT * FROM AcctName";
    > if (SortExpression != null)
    > SelectCommand += " ORDER BY " + SortExpression;
    >
    > OleDbConnection conn = new OleDbConnection(@"Provider=vfpoledb.1;User
    > Id=;Password=;Data
    >

    Source=C:\temp\dotnet1.1\asp\essentials\samples\mytesting\IntelligentOffice"
    > );
    > OleDbCommand cmd = new OleDbCommand( SelectCommand, conn );
    >
    > conn.Open();
    > IDataReader reader = cmd.ExecuteReader();
    > grdAccount.DataSource = reader;
    > grdAccount.DataBind();
    >
    > conn.Dispose();
    > }
    > }
    >
    >
    Rick Spiewak, Aug 26, 2003
    #3
  4. John,

    Sorry, but that was the only thing I could see that might have been wrong
    with your code...

    That said, I mostly program in VB.Net so maybe someone with more C#
    experience could spot something else to try.

    Good luck with it!

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "John Spiegel" <> wrote in message
    news:...
    > Thanks for getting involved! Unfortunately, I inserted a conn.Close()
    > before the conn.Dispose() and it appears to do the same thing (work first
    > time then die the second).
    >
    > FWIW, I'm using WebMatrix, the 1.1 version of .NET framework on a Win2K

    pro
    > machine.
    >
    > - John
    >
    > "S. Justin Gengo" <> wrote in message
    > news:#...
    > > John,
    > >
    > > Instead of Connection.Dispose();
    > >
    > > Use Connection.Close(); and then Connection.Dispose() instead.
    > >
    > > Connection.Dispose() tells the .Net garbage collector that it's okay to
    > > dispose of an object when it gets around to it. It does not close the
    > > connection.
    > >
    > > Sincerely,
    > >
    > > --
    > > S. Justin Gengo, MCP
    > > Web Developer
    > >
    > > Free code library at:
    > > www.aboutfortunate.com
    > >
    > > "Out of chaos comes order."
    > > Nietzche
    > >
    > >
    > > "John Spiegel" <> wrote in message
    > > news:...
    > > > Hi All,
    > > >
    > > > I've got the following .aspx file with the then following .cs code.

    The
    > > > page renders fine on first run, but once I click the submit, it just

    > comes
    > > > back with a cannot be displayed page indicating that the page is not
    > > > available. Anyone see what probably obvious or stupid thing I'm

    > missing?
    > > >
    > > > TIA,
    > > >
    > > > John
    > > >
    > > > Test.aspx:
    > > > ========
    > > >
    > > > <%@ Page Language="C#" Src="Temp.cs" Inherits="dgrdAccountSort" %>
    > > > <html>
    > > > <head>
    > > > </head>
    > > > <body>
    > > > <form runat="server">
    > > > <asp:datagrid id="grdAccount" runat="server" Height="100%"
    > > > Width="100%"></asp:datagrid>
    > > > <input type="submit" value="Submit Query" runat="server" />
    > > > </form>
    > > > </body>
    > > > </html>
    > > >
    > > >
    > > > Temp.cs code:
    > > > ==========
    > > > using System;
    > > > using System.Web;
    > > > using System.Web.UI;
    > > > using System.Web.UI.WebControls;
    > > > using System.Data;
    > > > using System.Data.OleDb;
    > > >
    > > > public class dgrdAccountSort : Page
    > > > {
    > > > private string SortExpression;
    > > > protected DataGrid grdAccount;
    > > >
    > > > protected void Page_Load(object Src, EventArgs e)
    > > > {
    > > > BindGridReader();
    > > > }
    > > >
    > > >
    > > > public void BindGridReader()
    > > > {
    > > > string SelectCommand = "SELECT * FROM AcctName";
    > > > if (SortExpression != null)
    > > > SelectCommand += " ORDER BY " + SortExpression;
    > > >
    > > > OleDbConnection conn = new

    OleDbConnection(@"Provider=vfpoledb.1;User
    > > > Id=;Password=;Data
    > > >

    > >

    >

    Source=C:\temp\dotnet1.1\asp\essentials\samples\mytesting\IntelligentOffice"
    > > > );
    > > > OleDbCommand cmd = new OleDbCommand( SelectCommand, conn );
    > > >
    > > > conn.Open();
    > > > IDataReader reader = cmd.ExecuteReader();
    > > > grdAccount.DataSource = reader;
    > > > grdAccount.DataBind();
    > > >
    > > > conn.Dispose();
    > > > }
    > > > }
    > > >
    > > >

    > >
    > >

    >
    >
    S. Justin Gengo, Aug 26, 2003
    #4
  5. John Spiegel

    John Spiegel Guest

    Not yet, I'll give it a shot! I did find some very similar code code that
    is working so I can use it to find my mistake. Thanks for the advice, Rick!

    - John

    "Rick Spiewak" <> wrote in message
    news:#...
    > Just a thought - have you tried closing the connection by setting the
    > commandbehavior of your command to do so after the Datareader is closed.

    And
    > then close the datareader after binding?
    >
    > "John Spiegel" <> wrote in message
    > news:...
    > > Hi All,
    > >
    > > I've got the following .aspx file with the then following .cs code. The
    > > page renders fine on first run, but once I click the submit, it just

    comes
    > > back with a cannot be displayed page indicating that the page is not
    > > available. Anyone see what probably obvious or stupid thing I'm

    missing?
    > >
    > > TIA,
    > >
    > > John
    > >
    > > Test.aspx:
    > > ========
    > >
    > > <%@ Page Language="C#" Src="Temp.cs" Inherits="dgrdAccountSort" %>
    > > <html>
    > > <head>
    > > </head>
    > > <body>
    > > <form runat="server">
    > > <asp:datagrid id="grdAccount" runat="server" Height="100%"
    > > Width="100%"></asp:datagrid>
    > > <input type="submit" value="Submit Query" runat="server" />
    > > </form>
    > > </body>
    > > </html>
    > >
    > >
    > > Temp.cs code:
    > > ==========
    > > using System;
    > > using System.Web;
    > > using System.Web.UI;
    > > using System.Web.UI.WebControls;
    > > using System.Data;
    > > using System.Data.OleDb;
    > >
    > > public class dgrdAccountSort : Page
    > > {
    > > private string SortExpression;
    > > protected DataGrid grdAccount;
    > >
    > > protected void Page_Load(object Src, EventArgs e)
    > > {
    > > BindGridReader();
    > > }
    > >
    > >
    > > public void BindGridReader()
    > > {
    > > string SelectCommand = "SELECT * FROM AcctName";
    > > if (SortExpression != null)
    > > SelectCommand += " ORDER BY " + SortExpression;
    > >
    > > OleDbConnection conn = new OleDbConnection(@"Provider=vfpoledb.1;User
    > > Id=;Password=;Data
    > >

    >

    Source=C:\temp\dotnet1.1\asp\essentials\samples\mytesting\IntelligentOffice"
    > > );
    > > OleDbCommand cmd = new OleDbCommand( SelectCommand, conn );
    > >
    > > conn.Open();
    > > IDataReader reader = cmd.ExecuteReader();
    > > grdAccount.DataSource = reader;
    > > grdAccount.DataBind();
    > >
    > > conn.Dispose();
    > > }
    > > }
    > >
    > >

    >
    >
    John Spiegel, Aug 26, 2003
    #5
  6. John Spiegel

    John Spiegel Guest

    I appreciate the time looking into it! It's been a long time since I've
    picked up a new language so now I'm trying to basically do two at once!
    Yea! <g>

    "S. Justin Gengo" <> wrote in message
    news:#...
    > John,
    >
    > Sorry, but that was the only thing I could see that might have been wrong
    > with your code...
    >
    > That said, I mostly program in VB.Net so maybe someone with more C#
    > experience could spot something else to try.
    >
    > Good luck with it!
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "John Spiegel" <> wrote in message
    > news:...
    > > Thanks for getting involved! Unfortunately, I inserted a conn.Close()
    > > before the conn.Dispose() and it appears to do the same thing (work

    first
    > > time then die the second).
    > >
    > > FWIW, I'm using WebMatrix, the 1.1 version of .NET framework on a Win2K

    > pro
    > > machine.
    > >
    > > - John
    > >
    > > "S. Justin Gengo" <> wrote in message
    > > news:#...
    > > > John,
    > > >
    > > > Instead of Connection.Dispose();
    > > >
    > > > Use Connection.Close(); and then Connection.Dispose() instead.
    > > >
    > > > Connection.Dispose() tells the .Net garbage collector that it's okay

    to
    > > > dispose of an object when it gets around to it. It does not close the
    > > > connection.
    > > >
    > > > Sincerely,
    > > >
    > > > --
    > > > S. Justin Gengo, MCP
    > > > Web Developer
    > > >
    > > > Free code library at:
    > > > www.aboutfortunate.com
    > > >
    > > > "Out of chaos comes order."
    > > > Nietzche
    > > >
    > > >
    > > > "John Spiegel" <> wrote in message
    > > > news:...
    > > > > Hi All,
    > > > >
    > > > > I've got the following .aspx file with the then following .cs code.

    > The
    > > > > page renders fine on first run, but once I click the submit, it just

    > > comes
    > > > > back with a cannot be displayed page indicating that the page is not
    > > > > available. Anyone see what probably obvious or stupid thing I'm

    > > missing?
    > > > >
    > > > > TIA,
    > > > >
    > > > > John
    > > > >
    > > > > Test.aspx:
    > > > > ========
    > > > >
    > > > > <%@ Page Language="C#" Src="Temp.cs" Inherits="dgrdAccountSort" %>
    > > > > <html>
    > > > > <head>
    > > > > </head>
    > > > > <body>
    > > > > <form runat="server">
    > > > > <asp:datagrid id="grdAccount" runat="server" Height="100%"
    > > > > Width="100%"></asp:datagrid>
    > > > > <input type="submit" value="Submit Query" runat="server" />
    > > > > </form>
    > > > > </body>
    > > > > </html>
    > > > >
    > > > >
    > > > > Temp.cs code:
    > > > > ==========
    > > > > using System;
    > > > > using System.Web;
    > > > > using System.Web.UI;
    > > > > using System.Web.UI.WebControls;
    > > > > using System.Data;
    > > > > using System.Data.OleDb;
    > > > >
    > > > > public class dgrdAccountSort : Page
    > > > > {
    > > > > private string SortExpression;
    > > > > protected DataGrid grdAccount;
    > > > >
    > > > > protected void Page_Load(object Src, EventArgs e)
    > > > > {
    > > > > BindGridReader();
    > > > > }
    > > > >
    > > > >
    > > > > public void BindGridReader()
    > > > > {
    > > > > string SelectCommand = "SELECT * FROM AcctName";
    > > > > if (SortExpression != null)
    > > > > SelectCommand += " ORDER BY " + SortExpression;
    > > > >
    > > > > OleDbConnection conn = new

    > OleDbConnection(@"Provider=vfpoledb.1;User
    > > > > Id=;Password=;Data
    > > > >
    > > >

    > >

    >

    Source=C:\temp\dotnet1.1\asp\essentials\samples\mytesting\IntelligentOffice"
    > > > > );
    > > > > OleDbCommand cmd = new OleDbCommand( SelectCommand, conn );
    > > > >
    > > > > conn.Open();
    > > > > IDataReader reader = cmd.ExecuteReader();
    > > > > grdAccount.DataSource = reader;
    > > > > grdAccount.DataBind();
    > > > >
    > > > > conn.Dispose();
    > > > > }
    > > > > }
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    John Spiegel, Aug 26, 2003
    #6
  7. John Spiegel

    John Spiegel Guest

    FYI, As it turns out, the error seems to be tied to my not limiting the
    amount of the table it displayed on the page. Once I narrowed it down to 20
    rows at a time, the error went away. I'm not clear as to whether that's a
    configurable limitation or not.

    - John

    "John Spiegel" <> wrote in message
    news:...
    > Hi All,
    >
    > I've got the following .aspx file with the then following .cs code. The
    > page renders fine on first run, but once I click the submit, it just comes
    > back with a cannot be displayed page indicating that the page is not
    > available. Anyone see what probably obvious or stupid thing I'm missing?
    >
    > TIA,
    >
    > John
    >
    > Test.aspx:
    > ========
    >
    > <%@ Page Language="C#" Src="Temp.cs" Inherits="dgrdAccountSort" %>
    > <html>
    > <head>
    > </head>
    > <body>
    > <form runat="server">
    > <asp:datagrid id="grdAccount" runat="server" Height="100%"
    > Width="100%"></asp:datagrid>
    > <input type="submit" value="Submit Query" runat="server" />
    > </form>
    > </body>
    > </html>
    >
    >
    > Temp.cs code:
    > ==========
    > using System;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    > using System.Data;
    > using System.Data.OleDb;
    >
    > public class dgrdAccountSort : Page
    > {
    > private string SortExpression;
    > protected DataGrid grdAccount;
    >
    > protected void Page_Load(object Src, EventArgs e)
    > {
    > BindGridReader();
    > }
    >
    >
    > public void BindGridReader()
    > {
    > string SelectCommand = "SELECT * FROM AcctName";
    > if (SortExpression != null)
    > SelectCommand += " ORDER BY " + SortExpression;
    >
    > OleDbConnection conn = new OleDbConnection(@"Provider=vfpoledb.1;User
    > Id=;Password=;Data
    >

    Source=C:\temp\dotnet1.1\asp\essentials\samples\mytesting\IntelligentOffice"
    > );
    > OleDbCommand cmd = new OleDbCommand( SelectCommand, conn );
    >
    > conn.Open();
    > IDataReader reader = cmd.ExecuteReader();
    > grdAccount.DataSource = reader;
    > grdAccount.DataBind();
    >
    > conn.Dispose();
    > }
    > }
    >
    >
    John Spiegel, Aug 26, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. alanb
    Replies:
    2
    Views:
    520
    alanb
    Apr 23, 2004
  2. Mike
    Replies:
    3
    Views:
    596
    Andrew Thompson
    Sep 16, 2004
  3. Aparna
    Replies:
    1
    Views:
    4,229
    HalcyonWild
    Oct 10, 2005
  4. as mellow as a horse

    Newbie stuck posting to an ASP page

    as mellow as a horse, May 10, 2004, in forum: HTML
    Replies:
    6
    Views:
    425
    as mellow as a horse
    May 10, 2004
  5. AmitKu
    Replies:
    7
    Views:
    499
    John Timney \(MVP\)
    Jan 8, 2007
Loading...

Share This Page