mithrandyr / SimplySql

PowerShell module for querying various SQL databases
MIT License
197 stars 31 forks source link

Exception calling "Fill" with "1" argument(s): "Unable to convert MySQL date/time value to System.DateTime". #122

Closed Myjestic closed 8 months ago

Myjestic commented 10 months ago

Running on Debian with pwsh7. If I connect with Open-MySqlConnection -server $dbHost -connectionname 'localhost' -database $dbName -UserName $dbUser -Password $dbPass and execute a query, the following error occures because of wrong date values in my database.

Exception: /opt/microsoft/powershell/7/Modules/SimplySql/1.9.1/Providers/MySql/provider.ps1:42
Line |
  42 |              $da.Fill($ds)
     |              ~~~~~~~~~~~~~
     | Exception calling "Fill" with "1" argument(s): "Unable to convert MySQL date/time value to System.DateTime"

I was able to solve the issue by connecting like this: Open-MySqlConnection -ConnectionName 'localhost' -ConnectionString "convert zero datetime=true;server=localhost;Database=mydatabase;Uid=myuser;Pwd=mypassword;CHARSET=utf8"

Maybe you could implement "convert zero datetime=true" in your routine.

mithrandyr commented 8 months ago

@Myjestic -- interesting suggestion -- version 1.9 does not support PowerShell 7 yet (so if it works, great.. if not...)... I'm almost finished with 2.0 which is a complete rewrite to fully support PowerShell 7 (and cross platform). 2.0 will also switch the underlying provider for MySql, which may improve this experience (and avoid the need for additional connection parameter). However, if it doesn't, 2.0 also support providing arbitrary additional connection parameters without having to construct the connection string manually, so that would also solve for this particular scenario.

I try to avoid putting things into the connection string that might be situation specific.