0

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#

0

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Please point out servername in connection string as pattern:

string myConnection
    = "Server="+myServerAddress+";Database="+myDataBase+";Uid="+myUsername+";Pwd="+myPassword;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.