mithrandyr / SimplySql

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

MariaDB: Object cannot be cast from DBNull to other types #112

Closed oNdsen closed 1 year ago

oNdsen commented 1 year ago

There is a Problem with MariaDB > 10.9 Details: https://stackoverflow.com/questions/74060289/mysqlconnection-open-system-invalidcastexception-object-cannot-be-cast-from-d

Edit: Only workaround for me i found is to remove the throw and retry the connection.

Loop:

# db connection
$retry = 0
do {
    Write-Log -Text "Verbose: Trying to open MySQL Connection"

    Open-MySqlConnection -Server $global:conf.sql.host -Database $global:conf.sql.db -Credential $sqlCreds -ConnectionName $global:conf.sql.db
    if(!$(Show-SqlConnection -ConnectionName $global:conf.sql.db))
    {
        $retry += 1
        Write-Log -Text "Verbose: MySQL Connection failed - retry $retry/5"
        Start-Sleep -Seconds 1
    }
}
until ($(Show-SqlConnection -ConnectionName $global:conf.sql.db) -or $retry -eq 5)
mithrandyr commented 1 year ago

@oNdsen -- I'm currently working (in my spare time between grad school + work) on version 2.0 which will include moving away from current MySQL provider (MySql.Data.MySqlClient) to MySqlConnector, as well as supporting Powershell 7 and Windows Powershell 5.1. Once version 2.0 comes out, this issue should be addressed.

impsj commented 1 year ago

Is there a patch during that time? The latest version of MariaDB working with SimplySql is 10.6. They are now at version 11.2.