[Mono-bugs] [Bug 74856][Wis] New - SQL Server bigint type is treated as Decimal instead of Int64

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 7 May 2005 05:00:18 -0400 (EDT)


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 sherif.elmetainy@gmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=74856

--- shadow/74856	2005-05-07 05:00:18.000000000 -0400
+++ shadow/74856.tmp.14600	2005-05-07 05:00:18.000000000 -0400
@@ -0,0 +1,58 @@
+Bug#: 74856
+Product: Mono: Class Libraries
+Version: 1.1
+OS: GNU/Linux [Other]
+OS Details: Fedora Core 3
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Sys.Data
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: sherif.elmetainy@gmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: SQL Server bigint type is treated as Decimal instead of Int64
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+SqlDataReader.GetInt64 would throw an InvalidCastException for a column of 
+type bigint returned from SQL Server
+
+Steps to reproduce the problem:
+1. Create a SQL server table with a bigint field: CREATE TABLE MyTable 
+(MyField bigint)
+2. Insert any value in the table
+INSERT INTO MyTable (MyField) VALUES (123)
+3. Run the following code
+SqlConnection conn = new SqlConnection(connectionString);
+conn.Open();
+SqlCommand cmd = new SqlCommand("SELECT MyField FROM MyTable", conn);
+SqlDataReader reader = cmd.ExecuteReader();
+reader.Read();
+decimal decimalValue = reader.GetDecimal(0);
+long longValue = reader.GetInt64(0);
+
+Actual Results:
+GetDecimal doen't throw an exception
+GetInt64 throws an InvalidCastException with message "Type is 
+System.Decimal"
+
+Expected Results:
+GetDecimal should throw an InvaliCastException
+GetInt64 shouldn't throw an Exception
+
+How often does this happen? 
+Always
+
+Additional Information:
+I am able to reproduce this bug on mono version 1.1.7 and Fedora Core 3. I 
+didn't test on other versions or operating systems, but I think the OS 
+doesn't matter here.
+
+Work Around:
+use Convert.ToInt64(reader.GetValue(0)). This should work on mono and 
+Microsoft .NET