c# - 访问数据库连接字符串错误

标签 c# argumentexception

所以我在本地主机上创建了一个网站,我在 C:\inetpub\wwwroot\Lollipops\App_Data\lollipopDB.mdb 中有一个数据库,我需要在我的网站上使用它,但是当我尝试在它,它一直给我错误:“System.ArgumentException:不支持关键字:‘provider’。”

这是在我的 web.config 文件中 -

< connectionStrings>
  < add name="lollipopDB" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\inetpub\wwwroot\Lollipops\App_Data\lollipopDB.mdb;" providerName="System.Data.OleDb" />
< /connectionStrings>

并且该网站调用函数 PerformSQL,该函数采用连接字符串的名称和要运行的 sql 字符串。

public void PerformSQL(string conn, string sqlStr)
{
    sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings[conn].ConnectionString;
    sql.CommandText = sqlStr;
    sql.Connection = sqlConn; //specify connection string for the command instance
    sqlConn.Open();
    sql.ExecuteNonQuery();
    sqlConn.Close();
}

最佳答案

sqlConn 的类型是什么?

需要是OleDbConnection。同样,命令需要是 OleDbCommand。

关于c# - 访问数据库连接字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1831260/

相关文章:

c# - 拆分 ;然后在 = 上,使用 String.Split 时遇到问题,需要正则表达式

c# - 对于以 '{' 开头的名称,为什么 XName.Get 抛出 ArgumentException 而不是 XmlException ?

windows-phone-7 - 为什么 HttpNotificationChannel.Open 抛出 ArgumentException() E_INVALIDARG?

c# - EPPlus 多个选项卡 c#

c# - WinForms 编程 - 模态和非模态表单问题

c# - 如何在阅读器关闭之前返回 MySqlDataReader

c# - 取消 Azure 服务总线 QueueClient 长时间运行的接收吗?

c# - 表达式...我做错了什么?

c# - Application.Run 抛出 ArgumentException 未处理

.net - 为什么FormatException不继承自ArgumentException?