Bug 8574 - Missing sqlCommand.Parameters.Clear() do not cause exception when a Parameter already exists
Summary: Missing sqlCommand.Parameters.Clear() do not cause exception when a Parameter...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.5.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-11-23 12:21 UTC by Karl Heinz Brehme Arredondo
Modified: 2017-01-04 04:43 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Karl Heinz Brehme Arredondo 2012-11-23 12:21:35 UTC
I'm porting iOS app to ASP.NET, to mantain the same .cs files libraries and pages (System.Windows.Forms : UIViewcontroller) and noticed a mistake in my code that do not cause excpetion in MonoTouch but on ASP.NET it crashed.

If I have a sqlCommand that received a parameter like

sqlCommand.Parameters.AddWithValue("@Parameter1", value);

And then if I have the below code:

			using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
				// Do things 
				while (sqlDataReader.Read())
					wasRead = Strings.ToNullableBoolean(sqlDataReader["wasRead"]);
					if (wasRead.HasValue)
						if (wasRead.Value)
							// Do things 
							// Do things 
						// Do things 
			sqlCommand.CommandText = SecondQuery;
			sqlCommand.Parameters.AddWithValue("@Param1", Value1); // Already exists
			sqlCommand.Parameters.AddWithValue("@Param2", Value2);

Then in ASP.NET it crashes and MonoTouch don't, because I forgot sqlCommand.Parameters.Clear().
Although this could be a more smart ling like reuse the parameter without needing to Clear() and be more quickly I feel that this was a mistake on my code that could be blocked at runtime, so I don't know if it is a bug on MonoTouch/Mono.Data.Sqlite compared to System.Data.SqlClient or not, nor if this happens on Android.

Comment 1 Alex Soto [MSFT] 2017-01-04 04:43:46 UTC
This seems to be the intended behaviour in Mono.Data.Sqlite you can reuse the parameters, that said if you use System.Data.SqlClient you should get the same behavior since we now match .NET source.