gpt4 book ai didi

c# - 需要 C# 中 web.config 中 Mysql 数据库连接的帮助

转载 作者:行者123 更新时间:2023-11-29 13:43:49 26 4
gpt4 key购买 nike

当我尝试在 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);
}

我得到的错误如下

Server Error in '/WebSite1' Application. Keyword not supported. Parameter name: respect binary flags Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Keyword not supported. Parameter name: respect binary flags

Source Error:

   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);

请帮助我。

最佳答案

你真的需要这个参数吗?你能把它拿出来吗?即,将连接字符串更改为

<add name="MyConn" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;User ID=root;Password=demo@123;Database=pay2school;port=3306;pooling=false;"/>

关于c# - 需要 C# 中 web.config 中 Mysql 数据库连接的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17723643/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com