VB.NET & MySQL, format of the initialization string does not conform to specification
Hey guys,
I've got a remote server running on my Pi and am currently trying to access it using vb.net 4.0 and failing. my code is
Imports MySql.Data.MySqlClient
Module Module1
Dim mysqlconn As MySqlConnection
Sub Main()
Try
mysqlconn = New MySqlConnection
mysqlconn.ConnectionString = "Server='000.000.000.000';Port='3306';Database='test1';Uid='Player'@'%';Pwd='PASS123';"
mysqlconn.Open()
mysqlconn.Close()
mysqlconn.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
My.Computer.Clipboard.SetText(ex.Message)
End Try
End Sub
End Module
the error message that i get is "Format of the initialization string does not conform to specification starting at index 54."
5 answers
The Uid='Player'@'%'; part looks strange... what's that?
If you really want single quotes in that value maybe you should surround the whole value with escaped double quotes. Like this: Uid=""Player'@'%"";
"" is VB.Net escaped ".
To put ' in the value the value can't be surrounded with '.
all information that i have used to make this program can be found at https://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-connecting-connection-string.html.
In the example it says to use the connection string syntax "Server=127.0.0.1;Uid=root;Pwd=12345;Database=test;", which i tried and got an error "Unable to connect to any of the specified MySQL hosts.", where as when i use " ' " around all data i get an error pointing to an index location.
I have tried using " "" " to no success.
Ok. But is the user name really
Player'@'%
???
I think that's the value messing it up for you...
And also, where is your server located? On the same machine? You need to know the address to the MySQL machine.... 127.0.0.1 means same machine.
The server is located on my Raspberry Pi which i know the local and global ip address for.
Because the DB should be assailable from any computer running the software i have set up a user Player@%
You should just leave the @'%' off. Just Uid='Player' will work fine. Your computer's name will be added, but the MySQL server will accept it because you allowed access for any computer name when you granted privileges to 'Player'@'%'. % is a wild card.