Please do not reply to this email- if you want to comment on the bug, go to the URL shown below and enter your comments there.
Changed by [EMAIL PROTECTED] http://bugzilla.ximian.com/show_bug.cgi?id=82189 --- shadow/82189 2007-07-25 17:01:58.000000000 -0400 +++ shadow/82189.tmp.23866 2007-07-25 17:01:58.000000000 -0400 @@ -0,0 +1,108 @@ +Bug#: 82189 +Product: Mono: Class Libraries +Version: 1.2 +OS: All +OS Details: +Status: NEW +Resolution: +Severity: +Priority: Normal +Component: Sys.Data.SqlClient +AssignedTo: [EMAIL PROTECTED] +ReportedBy: [EMAIL PROTECTED] +QAContact: [EMAIL PROTECTED] +TargetMilestone: --- +URL: +Cc: +Summary: SqlConnection throws an exception if Connection or Transaction is set to null + +Description of Problem: +Setting the Command or Transaction properties on a +System.Data.SqlClient.SqlCommand to null results in an exception if the +object is referenced as an IDbCommand. +Specifically Connection throws an InvalidCastException and Transaction +throws an ArgumentException. +In the Microsoft implementation, these do not throw exceptions. +See the Additional Information for more on the exceptions. + +Steps to reproduce the problem: +SqlConnection connection = new SqlConnection (_connectionString); +IDbCommand idbCommand = new SqlCommand (_query, connection); +idbCommand.Connection = null; +idbCommand.Transaction = null; + + +Actual Results: +ArgumentException/InvalidCastException is thrown. + +Expected Results: +Transaction/Connection set to null. + +How often does this happen? +Every time. + +Additional Information: +This is an identical problem to bug 78765, except this is with SqlCommand +instead of OracleCommand. +I don't know if they are supposed to throw InvalidCastExceptions or +ArgumentExceptions (the resolution for bug 78765 causes both to throw +InvalidCastExceptions). +Below are two possible fixes, the first allows null assignment in the +current code while allowing the type of exception thrown to be decided. +The second uses the same code as the bugfix for OracleCommand, and throws +InvalidCastException in both cases. + + +The current code is (for SqlConnection, SqlTransaction is similar): + IDbConnection IDbCommand.Connection { + get { return Connection; } + set { + if (!(value is SqlConnection)) + throw new InvalidCastException ("The value was not a valid +SqlConnection."); + Connection = (SqlConnection) value; + } + } + IDbTransaction IDbCommand.Transaction { + get { return Transaction; } + set { + if (!(value is SqlTransaction)) + throw new ArgumentException (); + Transaction = (SqlTransaction) value; + } + } + + +The new code could be either: + IDbConnection IDbCommand.Connection { + get { return Connection; } + set { + if (!(value == null || value is SqlConnection)) + throw new InvalidCastException ("The value was not a valid +SqlConnection."); + Connection = (SqlConnection) value; + } + } + IDbTransaction IDbCommand.Transaction { + get { return Transaction; } + set { + if (!(value == null || value is SqlTransaction)) + throw new ArgumentException (); + Transaction = (SqlTransaction) value; + } + } + +or + + IDbConnection IDbCommand.Connection { + get { return Connection; } + set { + Connection = (OracleConnection) value; + } + } + IDbTransaction IDbCommand.Transaction { + get { return Transaction; } + set { + Transaction = (SqlTransaction) value; + } + } _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
