Reputation: 1
I'm trying to make my mysql connection string read from textbox instaid of direct string what i was trying to do is this
string myConnection = "datasource='" + this.label12 + "';username='" + this.textBox3 + "';password='" + this.textBox4 + "';SSL Mode=Required;Certificate Store Location=CurrentUser;";
And i get the error cannot connect to any mysql server
Coded in c#
Upvotes: 0
Views: 876
Reputation: 1167
Please point out servername in connection string as pattern:
string myConnection
= "Server="+myServerAddress+";Database="+myDataBase+";Uid="+myUsername+";Pwd="+myPassword;
Upvotes: 1
Reputation: 66449
You're trying to use label12
and textBox3
directly, which implicitly calls ToString()
on the object, and usually just returns the type of object (like "System.Windows.Controls.Label").
Use the Text
property of your labels and text boxes. (I also used String.Format
for readability.)
var myConnection
= string.Format("datasource='{0}';username='{1}';password='{2}';SSL Mode=Required;Certificate Store Location=CurrentUser;",
label12.Text, textBox3.Text, textBox4.Text);
I don't know if the connection string you're building will work. You may want to check out connectionstrings.com for samples.
Upvotes: 1