SCM

[#1010400] Proper NpgsqlException on connection errors

View Trackers | Patches | Download .csv | Monitor

Date:
2008-05-27 02:36
Priority:
3
State:
Open
Submitted by:
Cody Konior (cody)
Assigned to:
Nobody (None)
Category:
Group:
Resolution:
None
 
Summary:
Proper NpgsqlException on connection errors

Detailed description
The NpgsqlException class has some interesting properties like Code and Severity to help a client determine what it should do with the exception, but these aren’t set by the Open() subroutine. I propose a small change to set these properties to the sqlclient_unable_to_establish_sqlconnection error defined at <http://postgresql.com.cn/docs/8.3/static/errcodes-appendix.html> when the open fails. Or if you just like the idea you can implement it in some cleaner fashion.

NpgsqlClosedState.cs:
Line 29:
Using System.Collections.Generic;
Line 191, change the catch to:
// Fake sqlclient_unable_to_establish_sqlconnection to give clients an opportunity
// to do some automatic error handling.
List<NpgsqlError> errors = new List<NpgsqlError>();
errors.Add(new NpgsqlError(e.message, “FATAL”, “08001”));
throw new NpgsqlException(errors);

NpgsqlError.cs
Line 278:
// An optional constructor used to fake an error message.
Internal NpgsqlError(String errorMessage, String severity, String code)
{
_message = errorMessage;
_severity = severity;
_code = code;
}

Followup

Message
Date: 2008-06-02 16:59
Sender: Cody Konior

On second thoughts this should be "ERROR" instead of "FATAL".

I've made a similar change in NpgsqlCommands.cs to give an
08006 error ...


Line 33
Imports System.Collections.Generic;

Line 1446, in ClearPoolAndCreateException
(Remove: return new
NpgsqlException(resman.GetString("Exception_ConnectionBroken"),
e);

// Fake connection_failure to give clients an opportunity to do
// some error handling on their side.
List<NpgsqlError> errors = new List<NpgsqlError>();
errors.Add(new
NpgsqlError(resman.GetString("Exception_ConnectionBroken") +
": " + e.ToString(), "ERROR", "08006"));
return new NpgsqlException(errors);

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge