Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Invalid cast from 'System.String' to 'System.TimeSpan'." is thrown when getting value of output parameter which its type is TIME #680

Closed
nhathongly opened this issue Aug 14, 2019 · 7 comments
Assignees
Labels

Comments

@nhathongly
Copy link

@nhathongly nhathongly commented Aug 14, 2019

I got this exception when trying get the output value of TIME

System.InvalidCastException : Invalid cast from 'System.String' to 'System.TimeSpan'.
 StackTrace:
   at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
   at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType)
   at MySqlConnector.Core.DbTypeMapping.DoConversion(Object obj) in C:\projects\mysqlconnector\src\MySqlConnector\Core\DbTypeMapping.cs:line 22
   at MySqlConnector.Core.StoredProcedureCommandExecutor.SetParams() in C:\projects\mysqlconnector\src\MySqlConnector\Core\StoredProcedureCommandExecutor.cs:line 108
   at MySql.Data.MySqlClient.MySqlCommand.ReaderClosed() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 452
   at MySql.Data.MySqlClient.MySqlDataReader.DoClose() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 445
   at MySql.Data.MySqlClient.MySqlDataReader.Dispose(Boolean disposing) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 282
@bgrainger
Copy link
Member

@bgrainger bgrainger commented Aug 14, 2019

It looks like you might be using a stored procedure with an OUT parameter. Can you provide more details on how to reproduce this, e.g., table definition, stored procedure definition, sample code?

@nhathongly
Copy link
Author

@nhathongly nhathongly commented Aug 14, 2019

My stored procedure is simply like this

CREATE DEFINER=`root`@`%` PROCEDURE `GetTime`(OUT OutTime TIME)
BEGIN
	SET OutTime = CURTIME();
END

I'm totally new to MySql, so I don't know if I get any mistake. It worked perfectly with MySql.Data-8.0.16

@nhathongly
Copy link
Author

@nhathongly nhathongly commented Aug 30, 2019

Hi there,

I experienced the same issue when the data type of OUTPUT parameter is BOOL. The exception said that "Object of type 'System.SByte' cannot be converted to type 'System.Boolean'." when I tried to map the OUTPUT to a bool variable.
Could you have a check?

Thanks

@nhathongly
Copy link
Author

@nhathongly nhathongly commented Aug 30, 2019

When I executed the following script, I saw that the DTD_IDENTIFIER value in information_schema.parameters of a BOOL parameter was TINYINT(1)

SELECT ORDINAL_POSITION, PARAMETER_MODE, PARAMETER_NAME, DTD_IDENTIFIER
FROM information_schema.parameters
WHERE SPECIFIC_SCHEMA = 'DB Name' AND SPECIFIC_NAME = 'Routine Name'
ORDER BY ORDINAL_POSITION;
ORDINAL_POSITION PARAMETER_MODE PARAMETER_NAME DTD_IDENTIFIER
1 IN js json
2 OUT b tinyint(1)

@nhathongly
Copy link
Author

@nhathongly nhathongly commented Aug 30, 2019

Seem it will be fixed when 782a765 is released

@bgrainger may I know when will we have the next release? Thank you in advance

@bgrainger
Copy link
Member

@bgrainger bgrainger commented Aug 30, 2019

I'll release 0.57.0-beta9 with this fix soon. The beta versions are tested and reliable enough to run in production; they just haven't shipped as a "stable" release yet due to breaking API changes in this series.

@bgrainger
Copy link
Member

@bgrainger bgrainger commented Aug 30, 2019

0.57.0-beta9 is available with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants