Bugs
Search the entire project
This project's trackers
This project's forums
This project's tasks
This project's releases
This project's documents
This project's news
Project
People
Skill
Advanced search
Log In
|
New Account
Home
My Page
Projects
Code Snippets
Project Openings
Npgsql .Net Data Provider for Postgresql
Summary
Activity
Forums
Tracker
Lists
Tasks
Docs
Surveys
News
SCM
Files
[#1011220] System.ObjectDisposedException when accessing State
View Trackers
|
Bugs
|
Download .csv
|
Monitor
Date:
2012-08-27 08:43
Priority:
3
State:
Open
Submitted by:
Jochen Wezel (
jwezel
)
Assigned to:
Nobody (None)
Npgsql Version:
2.0.12beta
Category:
Group:
Resolution:
None
Summary:
System.ObjectDisposedException when accessing State
Detailed description
THE SITUATION
Please see following code snippet:
----SNIP----
Dim npgconn As New Npgsql.NpgsqlConnection
'Check for State properties works as expected while not disposed
Console.WriteLine("Status: " & npgconn.State)
Console.WriteLine("FullStatus: " & npgconn.FullState)
npgconn.Dispose()
'Check for State properties should work even if disposed to be able to check for a closed connection
'BUG: accessing the State properties throw a System.ObjectDisposedException
Console.WriteLine("Status: " & npgconn.State)
Console.WriteLine("FullStatus: " & npgconn.FullState)
----/SNIP----
WHY IT'S A BUG:
1. Since throwing/catching exceptions consumes lot of time, it's better to check for an object state if it's valid or not - in general.
But currently, there is NO possibility to check for the connection object state without immediately throwing an exception.
2. other .NET data providers (e.g. System.Data.SqlClient.SqlConnection) also never throw an exception when accessing the state property even if the object is disposed
HOW IT SHOULD BE RESOLVED:
At least the state property should return a valid state info System.Data.ConnectionState.Closed as the other .NET data providers (e.g. System.Data.SqlClient.SqlConnection) do.
Followup
Message
Date: 2012-09-21 11:11
Sender:
Jochen Wezel
I Suggest a patch like following:
----SNIP----
Public Overrides ReadOnly Property State As ConnectionState
Get
If Me.isDisposed Then
Return ConnectionState.Closed
Else
...standard behaviour...
End If
End Get
End Property
----SNIP----
This will save lot of time since expensive try-catch for
ObjectDisposedException is not required any more (and makes
apps more robust) :-)
Date: 2012-08-27 13:54
Sender:
Josh Cooley
Do you expect to open a connection again after it has been disposed? I'm not sure we should commit to supporting that. If you aren't planning to open a connection again after it has been disposed, why do you want to check it's state? Why even keep it around?
Attached Files:
Changes:
No Changes Have Been Made to This Item