mithrandyr / SimplySql

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

ConnectionName parameter is not working #105

Closed crimsonread closed 1 year ago

crimsonread commented 1 year ago

Hello,

When I tried to establish SQL connection by Open-MySqlConnection with ConnectionName parameter, it is not working.

Open-MySqlConnection -Credential root -Database Mydatabase -ConnectionName "Test"

When I enter Get-SqlConnection, the warning message is displayed as below.

WARNING: There is no active SQL Connection.

However, do Open-MySqlConnection without ConnectionName parameter, it is working as expected.

PowerShell Version: 7.3 MySql Version: 8.0

mithrandyr commented 1 year ago

@crimsonread Its important to note that every cmdlet with a -ConnectionName parameter has a default value of 'default', thus the following are identical

Open-MySqlConnection -Credential root -Database Mydatabase -ConnectionName "default"
Open-MySqlConnection -Credential root -Database Mydatabase

In your case, if you want to retrieve the underlying connection object associated with the connectionName of "Test", then you will need to pass that ConnectionName to Get-SqlConnection like this:

Get-SqlConnection -ConnectionName "Test"

# otherwise, if you don't specify connection name
Get-SqlConnection
# then you are implicitly calling it like this
Get-SqlConnection -ConnectionName "default"

This holds true for each cmdlet that has a -ConnectionName parameter.