I'm having problems with the application we port to Mono.
(For reference, the .NET runtime is 4.0, and the mono version is 2.6.7.)
EDIT: this problem persists on Mono 2.10.2
As part of running the application, it reads data into memory. For this part, I just use the built-in SQL commands, but for some reason I see inconsistent behavior in Linux / Mono (when it all works in Windows / .NET).
I have a query that works fine in some scenarios, but not in others.
This specific example does not work:
var cmd = new SqlCommand("SELECT ID, Name, VATTerritoryID, NativeCurrencyID FROM PricingZones", conn); var reader = cmd.ExecuteReader(); var objectToLoad = new SomeObjectType(); while (reader.Read()) { objectToLoad.Property1 = reader.GetInt32(row.GetOrdinal("ID")); objectToLoad.Property2 = reader.GetString(row.GetOrdinal("Name")); objectToLoad.Property3 = reader.GetInt32(row.GetOrdinal("VATTerritoryID")); objectToLoad.Property3 = reader.GetInt32(row.GetOrdinal("NativeCurrencyID")); }
EDIT: for comparison, here that works :
var cmd = new SqlCommand("SELECT VATTerritoryID, ProductDescriptionID, VATBandID FROM VATTerritoryBandExceptions", conn); var reader = cmd.ExecuteReader(); var someOtherObjectToLoad = new SomeOtherObjectType(); while (reader.Read()) { someOtherObjectToLoad.Property1 = reader.GetInt32(row.GetOrdinal("VATTerritoryID")); someOtherObjectToLoad.Property2 = reader.GetString(row.GetOrdinal("ProductDescriptionID")); someOtherObjectToLoad.Property3 = reader.GetInt32(row.GetOrdinal("VATBandID")); }
I had suspicions that there are differences:
- The case (since I know this is different from windows / linux), but everything that fits in lowercase did not solve the problem.
- Column names (maybe Mono cares more about reserved words?), But it seems that instead of Name with the name [Name] or 'Name' there were no others
The error in the first case was:
[IndexOutOfRangeException: Array index is out of range.] at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
Assuming the returned result set does not have "column1".
(EDIT: this section has been updated a bit for clarity)
Oddly enough, if I do this:
var cmd = new SqlCommand("SELECT ID, Name, VATTerritoryID, NativeCurrencyID FROM PricingZones", conn); var reader = cmd.ExecuteReader(); var objectToLoad = new SomeObjectType(); while (reader.Read()) { Console.WriteLine("First row, first column is " + row.GetValue(0)); Console.WriteLine("First row, second column is " + row.GetValue(1)); Console.WriteLine("First row, third column is " + row.GetValue(2)); Console.WriteLine("First row, fourth column is " + row.GetValue(3)); }
Output:
First row, first column is 0 First row, second column is New Array index is out of range.
I suppose that in this case something strange happens with the Mono framework, but I cannot find the corresponding error report, and I cannot determine why this happens only in some cases, but not in others! Has anyone else had a similar experience?
EDIT: I changed some of the statements to match what was in the rejection request if there is a problem with reserved words or similar. Note that the query that I issue in the second case does indeed query four columns and apparently only returns two very strange (0 | New).