我不知道为什么会出现这个错误,我什么都试过了。我想将我的 webForm 连接到数据库 .accdb 当我使用 using(){} 时出现错误“不支持关键字:‘provider’” 这是代码:
web.config
<connectionStrings>
<add name="ConnectionString"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Manuel_2\Documents\Login.accdb"
providerName="System.Data.OleDb" />
</connectionStrings>
WebForm1
private static string conDB =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(connDB)) //here is the error
{
// .....
}
}
最佳答案
Aleksey Mynkov 说得对。但这里有更多详细信息,因为您需要更多说明。
您的 web.config 没问题。自动生成的 Visual Studios 连接字符串使用正确的设置。相反,在您的 webform1 文件中,您需要做两件事。
将
using System.Data.OleDb.OleDbConnection;
添加到文件顶部,并删除using System.Data.SqlConnection;
将您的 webform1 代码更改为:
private static string conDB = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; protected void Page_Load(object sender, EventArgs e) { using (OleDbConnection con = new OleDbConnection(conDB)) //here is the error { } }
关于c# - 不支持关键字 : 'provider' . 打开 SqlConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27387912/