Bug 29420 - Bug in System.Data - DataReader can't handle sql datatype "Date" and datatype "Time" correctly
Summary: Bug in System.Data - DataReader can't handle sql datatype "Date" and datatype...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data (show other bugs)
Version: 3.12.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-04-27 09:09 UTC by info
Modified: 2018-02-22 22:32 UTC (History)
2 users (show)

Tags:
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 GitHub or Developer Community 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:
Status:
RESOLVED FIXED

Description info 2015-04-27 09:09:24 UTC
Bug Description: Error in System.Data - DataReader can't handle sql datatype "Date" and datatype "Time" correctly

Created a testcase with monodevelop and compiled under monodevelop in Debian jessie 8 64(stable) with mono runtime 3.12.1 (http://download.mono-project.com/repo/debian). 

Database:Used SQL Server 2014

Mono/Debian Compiled binaries work as expected under Windows 7 64bit. 

binaries runs on debian but fails due to the 2 casting error (se comment in testcase code).


Expected output: The values insert in database

How to run the test:
1. Create a console application (Mono / .NET 4.5) with reference to System.Data
2. Create a database table named "ContentLocales" with fields "lastUpdatedDate" and "lastUpdatedTime"
3. Insert one new item in table "ContentLocales"
4. Update the console application with the correct connection string (variable "connectionString")

//################################# Code ##############################################//
//#####################################################################################//

//Database Columns definition in table ContentLocales
[lastUpdatedDate] [date] NOT NULL,
[lastUpdatedTime] [time](7) NOT NULL,

//Console Application
public static void Main (string[] args)
{
	const string connectionString="Data Source=aaa;Initial Catalog=yyy;User Id=sa;Password=xxx";


	using (SqlConnection connection=new SqlConnection(connectionString))
	{
		connection.Open ();
		SqlCommand command = new SqlCommand ("select * from ContentLocales",connection);
		SqlDataReader reader = command.ExecuteReader();
		//Read First row Date and time
		reader.Read ();
		//Bug - object is of type string - not DateTime
		DateTime lastUpdatedDate=(DateTime)reader["LastUpdatedDate"];
		//Bug - object is of type string - not TimeSpan
		TimeSpan lastUpdatedTime=(TimeSpan)reader["LastUpdatedTime"]; 

		Console.WriteLine ("First Line -  LastUpdatedDate:{0}     LastUpdatedTime:{1}", lastUpdatedDate, lastUpdatedTime);
	}
		
}
Comment 1 Marek Safar 2018-02-22 22:32:58 UTC
Mono 5.10 has significantly improved System.Data implementation which should resolve this issue. If you can still reproduce it please reopen the issue.