我正在尝试让我的mysql连接字符串从文本框中读取,而不是直接读取字符串。我尝试这样做
string myConnection = "datasource='" + this.label12 + "';username='" + this.textBox3 + "';password='" + this.textBox4 + "';SSL Mode=Required;Certificate Store Location=CurrentUser;";并且我得到了错误:无法连接到任何mysql服务器
在c#中编码
发布于 2014-06-13 08:49:13
您正尝试直接使用label12和textBox3,它们隐式地调用对象上的ToString(),并且通常只返回对象的类型(如"System.Windows.Controls.Label")。
使用标签和文本框的Text属性。(为了提高可读性,我还使用了String.Format。)
var myConnection
= string.Format("datasource='{0}';username='{1}';password='{2}';SSL Mode=Required;Certificate Store Location=CurrentUser;",
label12.Text, textBox3.Text, textBox4.Text);我不知道您正在构建的连接字符串是否可以工作。你可能想看看connectionstrings.com上的样例。
发布于 2014-06-13 10:22:44
请指出连接字符串中的servername为模式:
string myConnection
= "Server="+myServerAddress+";Database="+myDataBase+";Uid="+myUsername+";Pwd="+myPassword;https://stackoverflow.com/questions/24196065
复制相似问题