Replies: 1 comment 6 replies
-
@alive-one There is, I think, a small typo in your script that I believe is the source of the problem: # your original line, where you are opening the connection
Open-MySqlConnection -server '192.168.0.70' -connectionname 'localhost' -database 'pcinfo' -Credential Cred
# what the line should be, notice that instead of 'Cred', we now have '$Cred'
# in your line, you were passing the string value "Cred" to the -Credential Parameter
Open-MySqlConnection -server '192.168.0.70' -connectionname 'localhost' -database 'pcinfo' -Credential $Cred That should address the error you are receiving. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I have copyed example script from WIKI https://github.com/mithrandyr/SimplySql/wiki/Open-MySqlConnection
And changed it a bit so it is even simpler. It must just open connection, execure siple query and close connection.
Import-Module -Name SimplySQL
$password = ConvertTo-SecureString "mypass" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("sqlwriter", $password)
Open-MySqlConnection -server '192.168.0.70' -connectionname 'localhost' -database 'pcinfo' -Credential Cred
$testconnection = Test-SqlConnection -ConnectionName 'localhost'
if ($testconnection) {
$InsertQuery = "INSERT INTO table1 (value1, value2) VALUES (@label1, @label2)"
Close-SqlConnection -connectionname 'localhost'
}
But unfirtunately, I can not initiate a connection. I recieve PSCredential error, yet it is written according to all MS recomendations.
Here is an error:
Open-MySqlConnection: Cannot bind parameter "Credential". Cannot convert value "Cred" of type "System.String" to type "System.Management.Automation.PSCredential".
I doublechecked and I can connect to database with given credentials via MySQL Workbench. $Cred is also a PSCredential Object and password has "secure string" type
Beta Was this translation helpful? Give feedback.
All reactions