• 0

How can I handle oracle exceptions using Enterprise Library?


Question

I'm building an ASP.NET web application using C#, Enterprise Library and Oracle for a database. This is the first time I'm using Oracle as the database and so far my experience hasn't been all that great (I prefer using MS SQL Server). So here's the scenario:

The users have the ability to enter and change the value of a unique field in the database (e.g.- username). If the user enters a value (in this context, a username) which has been already entered as a different record then the requirement is to the inform the user as such. Since the inserting and/or updating is done via stored procedure I decided to handle the exception within the store procedure. I did so by declaring an out parameter called erCode of type NUMBER and added the following the block to the stored procedure after the SQL statement.


EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
erCode := SQLCODE
[/CODE]

In the event the INSERT/UPDATE operation was successful I return *erCode* with value 0.

Naturally since there was a return value an exception was never caught in the try-catch block of the code in the data access layer (DAL) of the application. Therefore I returned the value of *erCode* from DAL to the business logic layer (BLL) and then to the UI layer where I handled it [b]inside[/b] the try block by:

[CODE]
if (errorCode = -1)
{
lblMsg.Text = "Username already exists";
}
else
{
lblMsg.Text = "Username changed successfully";
}[/CODE]

I realise this is a horrible way to do this even if the oracle error code is a value apart from "-1", then the [i]Username changed successfully[/i] will be shown which would be completely misleading.

I'm not supposed to use the System.Data.OracleClient.OracleException class since its not looked upon favourably when we use that class in adjacent with Enterprise Library at my work place. If we are using Enterprise Library, then we should use that alone for all database related functions.

This bring me to my question; how can I handle such a scenario? Is it possible to do it using Enterprise Library alone?

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.