[NEWBIE]try .. catch .. not continuing on server error

Discussion in 'ASP .Net' started by Beemer Biker, Oct 31, 2006.

  1. Beemer Biker

    Beemer Biker Guest

    I put in a database operation in a try .. catch .. but I continue to get a
    server error.

    Sql_psg.SelectCommand = "DROP TABLE \"##TEMP\"";

    The above runs fine if ##TEMP exists. If not (the table does not exists)
    then I get a server error.

    If running VS2005 in debug and I have [x] checked for exceptions, then the
    error is thrown up in the debugger. After clicking on "continue" I still
    get the server error. So I get a server error both in the debugger and in
    the published web page.

    Is this functionality (continueing on after the "catch") a problem in the
    odbc postgresql drivers? There is no DROP TABLE IF EXISTS in postgresql,
    they dont even have an "IF command" in their sql syntax, so I was attempting
    to use the try..catch to ignore errors.

    I would have thought the code would continue on after the catch, but I guess

    ...thanks in advance..
    Beemer Biker, Oct 31, 2006
    1. Advertisements

  2. You catch exceptions raised on assigned the select command text. There won't
    be any. You need to catch exceptions in the code where the select is
    executed, not just assigned.
    Eliyahu Goldin, Oct 31, 2006
    1. Advertisements

  3. Beemer Biker

    Beemer Biker Guest

    thanks, but there seems that the code is executed during the assignement.
    There is no "active" nor "execute" like there is on windows forms. Is there
    Sql_psg.Active = true;
    that i missed?

    I am new into web projects. Using cbuilder and windows forms I have
    connections, datasets and datasources. All I have after installing posgresq
    odbc drivers is the "SqlDataSource". Looking at the VS8 toolbox, all the
    connections, datasets, datasources are grayed out when web projects is
    selected. Even the postgresql connection is grayed out.

    Is this the correct forum for web projects?

    Beemer Biker, Oct 31, 2006
  4. Yes, this is the most correct forum for web projects.

    Your select statement is executed by your datasource Select method during
    databinding. If you assign DataSourceID property in design time, databinding
    will take place automatically in PreRender event. To catch exceptions when
    the select runs, you need to control the databinding manually. There are
    many ways of doing this. You can assign the DataSourceID in run time and
    then call the DataBind method on the object bound to the datasource. If you
    enclose the DataBind call in try...catch, you will start catching

    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]

    Eliyahu Goldin, Oct 31, 2006
  5. Beemer Biker

    xAvailx Guest

    xAvailx, Oct 31, 2006
  6. Beemer Biker

    Beemer Biker Guest

    Thanks xAvailX. I attempted to create that function and the only language I
    could select was "SQL". "PLPGSQL" was not an option. It would appear the
    DB administrator did bother to install that language. It is supposed to be
    in the core distribution according to this download info:
    http://www.postgresql.org/download/ hopefully I can get the admin to
    install it. SQL does not accept IF whereas the procedural one does.
    Beemer Biker, Oct 31, 2006
  7. Beemer Biker

    Beemer Biker Guest

    Thanks Eliyahu. It still did not work, but I googled at "microsoft" and
    found this reference to "try catch html unhandled exception"
    I needed a Page_Error handler!
    Once I coded that up it received control when the SelectCommand failed.

    The SelectCommand triggered the exception and the debugger brought up the
    "debug" - continue" popup. Then I got that html unhandled error (that wasnt
    handled). None of those popups would even appear if I did not have [x]
    selected in the VS8 debug environment and irregardless they do not show up
    in the published page.

    Question: Where would I have looked to find the "Page_Error" event in the
    VS8 design object viewer? Right clicking on my Default.aspx form shows
    "document" as an object with no events. I would have expected an "Event"
    property such as "Page_Load" and "Page_Error". How would I know to use
    those other than poking around microsofts's msdn info browser?

    Beemer Biker, Oct 31, 2006
  8. Beemer Biker

    Beemer Biker Guest

    Correction: It receives control, but does not return to the catch.
    Context.ClearError(); clears the error but also erases the page and I am
    not back at the catch.

    I tried the following as you suggested:

    SqlDS_ViewAcquisition.SelectCommand = "DROP TABLE \"##TEMPVIEW\"";
    GridView1.DataSourceID = SqlDS_ViewAcquisition.ID;

    when the DataBind() is executed then this shows up.
    table "##TEMPVIEW" does not exist
    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: CoreLab.PostgreSql.PgSqlException: table "##TEMPVIEW"
    does not exist

    Source Error:

    An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of the
    exception can be identified using the exception stack trace below.

    Stack Trace:

    [PgSqlException (0x80004005): table "##TEMPVIEW" does not exist]
    CoreLab.PostgreSql.PgSqlCommand.a(CommandBehavior A_0, IDisposable A_1,
    Int32 A_2, Int32 A_3) +599
    CoreLab.Common.DbCommandBase.c(CommandBehavior A_0) +207
    behavior) +32
    System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
    DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
    srcTable, IDbCommand command, CommandBehavior behavior) +183
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
    Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
    behavior) +307
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
    arguments) +2866
    System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
    DataSourceViewSelectCallback callback) +84
    System.Web.UI.WebControls.DataBoundControl.PerformSelect() +154
    System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
    System.Web.UI.WebControls.GridView.DataBind() +24
    System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +91
    System.Web.UI.Control.EnsureChildControls() +134
    System.Web.UI.Control.PreRenderRecursiveInternal() +109
    System.Web.UI.Control.PreRenderRecursiveInternal() +233
    System.Web.UI.Control.PreRenderRecursiveInternal() +233
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4435
    Beemer Biker, Oct 31, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.