Home All Groups Group Topic Archive Search About

sqldatasource and connection exception handling

Author
16 Oct 2006 1:11 PM
Loic Transler
Hi,

In my page, I'm using a gridview and a sqldatasource. I don't know how to
handle the exception that occurs when the database server is unavailable.
I've read that I should use the execption property of the selected event.

But for this exception, the property is null.

How can I handle this exception ?


Thanks,

Loïc

Author
17 Oct 2006 4:22 PM
Michael Hamrah
I tried to replicate the problem and I'm getting the correct behavior-
the exception property is set.  Are you sure you're wiring up the
correct event?

//code behind
protected void SqlDataSource1_Selected(object sender,
SqlDataSourceStatusEventArgs e)
    {
        string s = e.Exception.Message;
    }

//page
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="..." SelectCommandType="StoredProcedure"
OnSelected="SqlDataSource1_Selected">


Loic Transler wrote:
Show quoteHide quote
> Hi,
>
> In my page, I'm using a gridview and a sqldatasource. I don't know how to
> handle the exception that occurs when the database server is unavailable.
> I've read that I should use the execption property of the selected event.
>
> But for this exception, the property is null.
>
> How can I handle this exception ?
>
>
> Thanks,
>
> Loïc
Author
18 Oct 2006 2:36 PM
Loic Transler
Hum... I realized that I was not working on the good sqldatasource... Sorry.

Thank you


Loïc


Show quoteHide quote
"Michael Hamrah" wrote:

> I tried to replicate the problem and I'm getting the correct behavior-
> the exception property is set.  Are you sure you're wiring up the
> correct event?
>
> //code behind
> protected void SqlDataSource1_Selected(object sender,
> SqlDataSourceStatusEventArgs e)
>     {
>         string s = e.Exception.Message;
>     }
>
> //page
>  <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
>             SelectCommand="..." SelectCommandType="StoredProcedure"
> OnSelected="SqlDataSource1_Selected">
>
>
> Loic Transler wrote:
> > Hi,
> >
> > In my page, I'm using a gridview and a sqldatasource. I don't know how to
> > handle the exception that occurs when the database server is unavailable.
> > I've read that I should use the execption property of the selected event.
> >
> > But for this exception, the property is null.
> >
> > How can I handle this exception ?
> >
> >
> > Thanks,
> >
> > Loïc
>
>