当我尝试在web.config中连接MySql数据库并在我的类文件中创建对象时,它会给我服务器错误。我的连接字符串如下。
<add name="MyConn" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;User ID=root;Password=demo@123;Database=pay2school;port=3306;pooling=false;respect binary flags=false"/>
我的Cs代码在
之下MySqlConnection conn = new MySqlConnection();
string datacon;
protected void Page_Load(object sender, EventArgs e)
{
datacon = ConfigurationManager.ConnectionStrings["MyConn"].ToString();
conn = new MySqlConnection(datacon);
//conn.ConnectionString = datacon;
// conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString);
Response.Write(conn);
}
我的错误低于
异常详细信息:System.ArgumentException:不支持关键字。 参数名称:尊重二进制标志
来源错误:
Line 20:
Line 21: datacon = ConfigurationManager.ConnectionStrings["MyConn"].ToString();
Line 22: conn = new MySqlConnection(datacon);
Line 23: //conn.ConnectionString = datacon;
Line 24: // conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString);
请帮助我。
答案 0 :(得分:1)
你真的需要那个参数吗?你能把它拿出来吗?即将连接字符串更改为
<add name="MyConn" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;User ID=root;Password=demo@123;Database=pay2school;port=3306;pooling=false;"/>
答案 1 :(得分:0)
使用ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString