Converting MS Oracle client to Oracle Data Provider - OracleException - c#

I'm converting a product from System.Data.OracleClient to Oracle.DataAccess.Client, and came across a question Here's a snippet of some code:
try
{
//some db code
}
catch (System.Data.OracleClient.OracleException ex)
{
if (ex.Code == 00904)
{
// log specific error
}
}
The problem is, Oracle.DataAccess.Client.OracleException has no Code property. It has a Number property. Is this the same thing? The docs say this about the property -
This error number can be the topmost level of error generated by
Oracle and can be a provider-specific error number.
The Code property contained the ORA- error code.

Yes, they are the same thing. Oracle.DataAccess.Client.OracleException.Number is the same info as System.Data.OracleClient.OracleException.Code.

Related

Error TF51635 Occurred while importing GlobalList using TFS REST API

I am importing GlobalList using TFS Rest API,
but getting the error below:
The server operation failed. (TF51635: There are duplicate temp IDs in
the Update XML. Parameter name: updateElement).
Sample code:
string text = System.IO.File.ReadAllText(SavDir + #"\Customer_Cleanze.xml");
try
{
workItemStore.ImportGlobalLists(text);
}
catch(Exception e){
Console.WriteLine(e.Message);
Console.WriteLine("Error Occured");
}
This XML list contains about 3K records. The strange thing is that when I try to import individual list item, it works fine means list item does not have an issue.
There is no documentation on Net, however, the similar issue posted here:
Can someone please help me in telling what is the wrong happening here?

Missing datagrid boundcolumn in production

Using visual studio and C#, I recently added a new bound column to a data grid and modified the stored procedure to pull the extra field. When I debug it - it shows up fine and displays the data as I expect. When I publish the website and copy the files to the web server, the column is no longer there. It's a pretty straight forward setup. I know the file is being copied etc. What am I missing?
In addition to the comments added above, make sure your added field exists on Production Database.
If it throws an exception that your code swallows up, you would never know.
Example:
private bool SomeMethod(string cmdText) {
bool result = false;
try {
result = Query(cmdText);
} Catch (Exception) {
// Error occurred
}
}
If you had the code above and had an error, you would never know.

Customize Sql Exception message in catch

I ´m doing a form where the user can Insert/Delete/Add entities. I´m using Winforms c# and entity framework 4.
Ok, the user can delete objects. Now, those objects can be referenced by other entities, so if the user wants to delete it, he will get an exception.
I catch that exception so as to show him a message that says that that object is begin used in other objects.
The exception I got is (UpdateException). But this exception can be raised if there is an update issue too. Is there any way to get the error code from Sql using this exception? Because I do have the error code that throws when this happens.
If I use SqlException I can check its number, but that's not the exception I´m receiving.
Do you mean you want to see the full exception or you want the user to the see the exception?
If you want to the see exception, you could write it to a text file:
try
{
// do something
}
catch(SQLException sqlex)
{
using (var file = new StreamWriter(#"C:\Users\Home\Desktop\sqlException.txt"))
{
file.WriteLine(sqlex.ToString());
}
}
catch(Exception e)
{
using (var file = new StreamWriter(#"C:\Users\Home\Desktop\generalException.txt"))
{
file.WriteLine(e.ToString());
}
}
This will write the exception to a text file on your desktop (change directories as appropriate).

How can I handle oracle exceptions using Enterprise Library in C#?

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
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 inside the try block by:
if (errorCode = -1)
{
lblMsg.Text = "Username already exists";
}
else
{
lblMsg.Text = "Username changed successfully";
}
I realise this is a horrible way to do this even if the oracle error code is a value apart from "-1", then the Username changed successfully 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?
If you need to take the code as what you are doing and still be on the safe side, then you can do like this:
When no error is encountered, then if I assume that ErrorCode
returned will be a null value, you may do this:
if(erCode==null)
errorCode = 1;
Setting ErrorCode =1 will certainly tell that operation was
success.
Modify your code as:
if (errorCode = -1)
{
lblMsg.Text = "Username already exists";
}
else if(errorCode = 1)
{
lblMsg.Text = "Username changed successfully";
}
else{
lblMsg.Text = "Unknown error while updating!";
}
So if there will be any other error code, relevant message is
shown!
Hope you find it worthy!

What happens if limit of Sql Server Compact Edition is reached?

What happens if a database reaches the limit of 4GB of the SQL Server Compact Edition? Is there a special exception for this?
Can I safely catch this event or exception and, let's say, create a new database?
I have not experienced this myself, but it looks like a SqlCeException will be thrown and the NativeError property of the contained SqlCeError will have an error code of 25104 (SSCE_M_DATABASETOOBIG).
Here's a listing of SqlCeError Native Codes related to db engine errors -- the one about the db file being too big is about 2/3 of the way down. The listing is for SQL CE 3.5; you didn't specify what version you were using, but I'm guessing that it wouldn't change.
I don't see why you couldn't catch this exception and then create a new database in your catch section.
try {
//do something
} catch (SqlCeException cexc){
foeach (SqlCeError aError in cexc.Errors) {
if (aError.NativeError == 25104) { //this is the code for the TOO BIG error code
//handle too big error -- maybe create a new database
}
}
}
I hope this helps!

Categories