C# - How To Catch Exception Occurred In DAL Of ObjectDataSource Object

Sep 1, 2010

I have ObjectDataSource and GridView on one of the pages of my asp.net web project.

To initialize ObjectDataSource i use Init event:

protected void ObjectDataSource1_Init(object sender, EventArgs e)
{
ObjectDataSource1.EnablePaging = true;
ObjectDataSource1.TypeName = "CustomerDataSource";
ObjectDataSource1.DataObjectTypeName = "Customer";
ObjectDataSource1.SelectMethod = "GetCustomers";
ObjectDataSource1.UpdateMethod = "Update";
ObjectDataSource1.SelectCountMethod = "GetCustomersCount";
ObjectDataSource1.MaximumRowsParameterName = "maximumRows";
ObjectDataSource1.StartRowIndexParameterName = "startRowIndex";
}

Somewhere in DAL:

public static List<Customer> GetCustomers(int maximumRows, int startRowIndex)
{
try {
... some select to database here...
}
catch (Exception ex)
{
Utils.LogError(ex);
throw ex;
}
}

Now let's imagine that GetCustomers for some reason throws an exception. How could i catch this exception and handle it? I know i can use Application_Error, but i would like to catch this exception somehow on my page and show some friendly message to the user.

View 1 Replies


Similar Messages:

Getting Unhandled Exception But Unable To Catch With Try Catch

Sep 14, 2011

I get this error in the browser:

Code:
Thread was being aborted.

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: System.Threading.ThreadAbortException: Thread was being aborted.

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:

[ThreadAbortException: Thread was being aborted.]
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +486
System.Web.ApplicationStepManager.ResumeSteps(Exception error) +501
System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +123
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +379

Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

I have try{}catch(Exception ex){} in the right place:

Code:
protected void Button1_Click(object sender, EventArgs e)
{
try
{
// all processing occurs inside here
}
catch(Exception ex)
{
}
}

I even created a global.asax file and on the Application_Error event, I wrote a code that would email me the error (and i'm not getting an email regarding that error when I get the error shown above). I know for a fact that the thread is going inside the "try" statement because I send emails to myself whenever it finishes certain codes inside of it. So how come I'm getting that error in my browser instead of it being handled in my "catch" statement? I have two problems here, one, why is the exception not going to my "catch" statement, and two, why am I getting that error in the first place.

Note: my web app calls a webservice.

View 2 Replies

DataSource Controls :: Getting Exception / An Exception Occurred While Executing A Transact-SQL Statement Or Batch

Jan 1, 2010

i need to restore Database.mdf; I create a blank new database exactly the same name as the .mdf file. However, I could not restore the database.

The error message prompted was:

TITLE: Microsoft SQL Server Management Studio Express

An exception occurred while executing a Transact-SQL statement or batch.

(Microsoft.SqlServer.Express.ConnectionInfo)

ADDITIONAL INFORMATION:

Cannot open backup device 'C:inetpubwwwrootTCPSystemApp_DataDatabase.mdf'. Operating system error 32(error not found).

RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3201)

click: [URL]

BUTTONS:

OK

View 10 Replies

Get Where The Exception Occurred?

Oct 13, 2010

I'm handling exceptions in the Application_Error() method in Global.asax but ex.Source is not giving me much. I want to know where the error occured i.e. /folderName/pageName.aspx.

Also I use lots of user controls so getting aspx name may not even be enough. Is there a way to get the name of object where the exception occured i.e. class name, user control name, etc.

View 1 Replies

A Critical Error Has Occurred / Object Reference Not Set To An Instance Of An Object

Aug 5, 2010

i have problem about when i try to login it cannot be perform, instead of it gives "A critical error has occurred. Object reference not set to an instance of an object." but user name can accepted but the password cannot be accepted.

View 4 Replies

How To Continue After Exception Occurred In C#

Nov 25, 2010

static string SomeMethodThatMightThrow(string s)
if (s[4] == 'C')
throw new InvalidOperationException();
return @"C:
ewFolder" + s;
static void Main(string[] args)
string[] files = { "fileA.txt", "B.txC", "fileC.txt","fileD.txt" };
[code]...

View 6 Replies

Continue After Exception Occurred In C#?

Jan 12, 2011

static string SomeMethodThatMightThrow(string s)
{
if (s[4] == 'C')

[code]...

View 3 Replies

ADO.NET :: Event Id 1309 - An Unhandled Exception Has Occurred

Oct 12, 2010

one of the sites hosted on our server is giving this error in event viewer

Event Type: Warning
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1309
Date: 24/06/2008
Time: 17:28:40
User: N/A
Computer:
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 24/06/2008 17:28:40
Event time (UTC): 24/06/2008 16:28:40
Event ID: 7addcd74d55746d3b73bf9905eb3edeb
Event sequence: 17
Event occurrence: 6
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/586182382/Root-1-128587971859459234
Trust level: Full
Application Virtual Path: /
Application Path: C:Inetpubconvex_crm
Machine name:
Process information:
Process ID: 6956
Process name: w3wp.exe
Account name: NT AUTHORITYNETWORK SERVICE
Exception information:
Exception type: InvalidOperationException
Exception message: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
Request information:
Request URL:
Request path: /Default.aspx
User host address: 192.168.23.52
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITYNETWORK SERVICE
Thread information:
Thread ID: 1
Thread account name: NT AUTHORITYNETWORK SERVICE
Is impersonating: False
Stack trace: at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Utils.GetOne(String query) in c:Inetpubconvex_crmApp_CodeUtils.cs:line 24
at Settings.GetSettings(String keyname) in c:Inetpubconvex_crmApp_CodeSettings.cs:line 17
at _Default.Page_Load(Object sender, EventArgs e) in c:Inetpubconvex_crmDefault.aspx.cs:line 19
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Custom event details: For more information, see Help and Support Center at [URL] the site was developed in ASP.NET 2.0 what might be the problem how to resolve it??

View 5 Replies

AJAX :: Threadabort Exception Occurred In Mscorlib.dll?

Oct 18, 2010

I get the following messages for whatever action I do with TabContainer and TabPanel controls.what should I do to get rid of these messages.A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll

An exception of type 'System.Threading.ThreadAbortException' occurred in.mscorlib.dll but was not handled in user code.

View 1 Replies

Stack Overflow Exception Error Occurred

Dec 19, 2011

I am getting this error..

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

Sub randgen()
Randomize()
rndum = ""
Dim i As Integer = 0
For i = 1 To 8
x = Int(Rnd() * 10)
rndum = rndum & x

[Code] ...
 
I am getting error at con.Open()

View 1 Replies

How To Throw And Catch Exception Handling

Oct 12, 2010

iam inserting record in three tables in a database, iam using begin trans , commit transaction and rollback,

i want to use throw method, if any value insert wrong, pls correct me, i want to throw the error and

its go to rollback

running = false;
int updaterec = DBmgr.ExecuteNonQuery(CommandType.Text, "update ASArrivedcontainer set billgen ='Y' where billgen ='y' and acontinerid in ("+SelValues+")");
if (updaterec > 0)
{
running = true;
DataSet BillContainerDetails = BillingDetails();
byte[] ContainerDetails = GenerateBill(DBmgr, sContainerIds, rcno,isGeneralRCNo, FetchContainerDetails, ModifyId,ref BillContainerDetails);
DBmgr.CreateParameters(6);
//string otherchargesId = obj.retriveSingleRecord("select top(1) ModifyId from ASOtherCharges");
DBmgr.AddParameters(0, "@InvoiceNo", "1","IN");
DBmgr.AddParameters(1, "@BillDate", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss tt"), "IN");
DBmgr.AddParameters(2, "@CustomerId", "1", "IN");
DBmgr.AddParameters(3, "@TotalAmount", "10000", "IN");
DBmgr.AddParameters(4, "@OtherChargesId", ModifyId, "IN");
DBmgr.AddParameters(5, "@ContainerDetails", ContainerDetails, "IN");
String BillNo = DBmgr.ExecuteScalar (CommandType.Text, "Insert into BillMaster(InvoiveNo,BillDate,CustomerId,TotalAmount,OtherChargesId,ContainerDetails) values (@InvoiceNo,@BillDate,@CustomerId,@TotalAmount,@OtherChargesId,@ContainerDetails)
Select @@Identity ").ToString();
if (!String.IsNullOrEmpty(BillNo))
{
running = true;
DBmgr.CreateParameters(4);
for (int i = 0; i < BillContainerDetails.Tables[0].Rows.Count; i++)
{
BillContainerDetails.Tables[0].Rows[i]["BillNo"] = BillNo;
DBmgr.AddParameters(0, "@Billno", BillContainerDetails.Tables[0].Rows[i].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@rcno", BillContainerDetails.Tables[0].Rows[i].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@acontinerid", BillContainerDetails.Tables[0].Rows[i].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@bflag", BillContainerDetails.Tables[0].Rows[i].ItemArray[4].ToString(), "IN");
//string value = BillContainerDetails.Tables[0].Rows[i].ItemArray[0].ToString(); ;
// string strsql = "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)Select @@Identity").ToString();
if (count > 1)
{
running = true;
}
else
{
}
//running = true ;
//break;
}
DBmgr.CreateParameters(6);
for (int j = 0; j < BillContainerDetails.Tables[1].Rows.Count; j++)
{
DBmgr.AddParameters(0, "@billcontkey", BillContainerDetails.Tables[1].Rows[j].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@ratetypcode", BillContainerDetails.Tables[1].Rows[j].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@days", BillContainerDetails.Tables[1].Rows[j].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@amount", BillContainerDetails.Tables[1].Rows[j].ItemArray[4].ToString(), "IN");
DBmgr.AddParameters(4, "@level", BillContainerDetails.Tables[1].Rows[j].ItemArray[5].ToString(), "IN");
DBmgr.AddParameters(5, "@sflag", BillContainerDetails.Tables[1].Rows[j].ItemArray[6].ToString(), "IN");
// string strsql = "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)Select @@identity ").ToString()
;

View 2 Replies

How To Catch All The Exception In One Place And Mail

May 13, 2010

i am almost finished up with a website and i have used this try catch block only in few places. now what i want is that i want to catch all the exception so that i can report the same through mail.. is it possible in any way to catch all the exception in one place and mail it cause now writing this block everywhere will be a kind of tedious process?

View 4 Replies

C# - Catch All Exception Handler In Global.cs?

Aug 10, 2010

What i would like to do is catch any exception that hasn't been handled in the web application then send the user to a screen saying something like

"Were sorry this has crashed"

And at the same time send the exception to our ticketing systems.

I am assuming I need to put it in the the global.cs somewhere just not sure where?

View 2 Replies

MVC Exception Not Being Caught In Try Catch Block?

Jan 21, 2010

I have tried this on two different controller methods now, and both times, even if the linq2sql doesn't allow the data to be saved, the code never jumps into the catch block.

I've watched the noun object in the middle of the trace, and the isvalid property is false, but the modelstate isvalid is true. Either way, the code never jumps into the catch block.I'm pulling my hair out about this. I feel like it will be something really silly.

The code all works similar to nerd dinner.

NounRepository nounRepository = new NounRepository();
Noun noun = new Noun();
try[code]...

I'd rather not have to add code in this manner though, as it seems like an unnecessary duplication.

View 3 Replies

C# - Unable To Catch Any Exception Properly?

Jun 16, 2010

In Asp.net (c#),i'm not able to catch exception(FileNotFoundException) properly... i don't know the reason..Actually File s not there..But catch statement fails to catch the exception..here is the code..

try
{
System.Drawing.Image imgg1 = System.Drawing.Image.FromFile(Server.MapPath("").ToString() + "\images\img1.jpg");
} [code]...

View 9 Replies

Unhandled Exception Occurred During The Execution Of The Current Web Request

Jun 8, 2010

I need values for 6 years that's 72months
if (i <= 72)
{
values[i] += C158_Calc;
}
B162_Calc = Financial.IRR(ref values, 0.1) * 12;
row9["Month1"] = String.Format("{0:#,###,###,###.##}", B162_Calc);
Description: An unhandled exception occurred during the execution of the current web request.

View 4 Replies

Unhandled Exception Has Occurred. Unknown Server Tag 'asp:ListView'?

Dec 2, 2010

Suddenly I got this message:

unhandled exception has occurred. unknown server tag 'asp:ListView'

What can be wrong with the project?

View 1 Replies

AJAX :: ChatRoom :- An Unhandled Exception Occurred ( Value Cannot Be Null )?

Jan 10, 2011

How can I use ChatRoom With Master page. If Run the Code then Follwing Error generatException Details: System.ArgumentNullException: Value cannot be null.Parameter name: StringSource Error:

[Code]....

Source File: ChatEngine.cs

protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null)

[code]...

View 1 Replies

Event Causing Error But Can't Catch Exception

Apr 22, 2010

A developer has created a custom control in ASP.NET using VB.NET. The custom control uses a repeater. In certain scenarios, the rpt_ItemDataBound event is encountering a data error. My goal is rather than having the user see the yellow screen of death, give the user a friendlier error explaining exactly what the data error is. I figured I would be able to use a Try/Catch block as shown below throw the exception, however, it appears that the event has nowhere to be thrown to and stops executing at the "End Try" line.

Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rpt1.ItemDataBound, rpt2.ItemDataBound
Try
ProcessBadData...
Catch ex As Exception
Throw ex
End Try
End Sub

In VB.NET, I can find where the repeater's DataSource is being set, however, I can not find a DataBind event. how I can capture the exception in this ASCX control so I can report it to the user? Edit: The stack trace looks like this. There is another repeater within the repeater that is actually causing the error (rptOther) and I'm able to catch the error, but I can only throw it to the rpt_ItemDataBound. I can't figure out how rpt_ItemDataBound is getting called without a DataBind event.

at Company.WebForms.Control.rptOther_ItemDataBound(Object sender, RepeaterItemEventArgs e)
at System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e)
at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.Repeater.DataBind()
at Company.WebForms.Control.rpt_ItemDataBound(Object sender, RepeaterItemEventArgs e)

View 1 Replies

Web Forms :: Validation Of Viewstate MAC Failed / An Unhandled Exception Occurred

Jul 6, 2010

my error

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Description:

An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

[code]....

View 3 Replies

An Unhandled Exception Occurred During The Execution Of The Current Web Request - How To Avoid It

May 6, 2010

in local it works. when i load server, i got this error.

Using themed css files requires a header control on the page. (e.g. <head runat="server" />).

Description:

An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Using themed css files requires a header control on the page. (e.g. <head runat="server" />).

[code]....

View 1 Replies

Unhandled Exception Occurred In W3wp.exe - Version: 7.5.7600.16385

Mar 8, 2011

I created a webform in 4.0 some users are saying they are getting the above error. I have windowsserver 2008, IIS 7 on it. Does anyone know how can I fix this issue?

View 5 Replies

Configuration :: Unhandled Win32 Exception Occurred In W3wp.exe When Run Application From IIS

Dec 20, 2010

an unhandled win32 exception occurred in w3wp.exe error occures when we run .Net application from IIS. My configuration is Windows server 2008, IIS7, .Net 2.0, and Oracle 10g.

View 2 Replies

Getting Error - An Unhandled Exception Occurred During The Execution Of The Current Web Request?

Feb 19, 2011

I am getting System.OutOfMemoryException exception in my Web Application (ASP.NEt with C# and MySql ) hosted on IIS.

The problem is popping up randomly once every few days when i enter username and password to enter..

What is the actual reason of this Error and suggest somthing to kill this problem permanently..

Server Error in '/' Application.

Exception of type 'System.OutOfMemoryException' was thrown.

Description:

An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

Source Error:

[Code]....

View 5 Replies

Configuration :: Event Code - 3005 An Unhandled Exception Has Occurred?

Nov 3, 2010

Actually I inherited this project, my job is enhance and debug this project. Just now my manager send me a log file ask me to debug, have no choose, I must settle this problem. according to the log file, I only know this bug occur in my login function,but I test in my local solution it can work well, no problem, it only appearing in live server. so I suspense it was server error, my manager ask me prove him, so any can explain to me what the log file mean? Event code: 3005

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved