简体   繁体   English

不支持的关键字:我的web.config文件中的“提供程序”错误

[英]Keyword not supported: 'Provider' error in my web.config file

I'm creating an ASP.NET page using C# that uses a connection string which is located in the Web.config file. 我正在使用C#创建一个ASP.NET页面,该页面使用位于Web.config文件中的连接字符串。 I'm also using an SQLDataSource Control in the page, which is seen here: 我还在页面中使用SQLDataSource控件,在这里可以看到:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
 ConnectionString="<%$ ConnectionStrings:AccessConnectionString %>"
 SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"
 UpdateCommand="UPDATE [Categories] SET [CategoryName] = @CategoryName, [Description] = 
 @Description WHERE [CategoryID] = @original_CategoryID">

As I said in the title, I'm getting an error that says Keyword not supported: 'Provider' I did some research on this error, and it seems as though I'm supposed to take out the "provider" part of my connection string, but I'm still confused as to what that means exactly. 就像我在标题中所说的那样,我收到一个错误消息, 提示不支持关键字:'Provider'我对此错误进行了一些研究,似乎我应该去掉连接的“提供者”部分字符串,但是我仍然对确切的含义感到困惑。 Here's my Web.config file here: 这是我的Web.config文件:

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>

<connectionStrings>

<add name="MyPubs" connectionString="Server=LOCALHOST; Database=pubs; User ID=ora000; 
Password=Pass000;" />

<add name="AccessConnectionString"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0; Data Source=|DataDirectory|Northwind.accdb;     
Persist Security Info=False; Jet
OLEDB:Database Password=;" providerName="System.Data.OleDb" />

</connectionStrings>

</configuration>

If I remove the word "provider" from the string, I just get a similar error message that says: Keyword not supported: followed by whatever characters are remaining in the Provider string. 如果我从字符串中删除单词“ provider”,则会收到类似的错误消息,内容为: 不支持的关键字:然后是提供程序字符串中剩余的任何字符。 I've been stuck on this for awhile, and I'm still very new to connections in ASP.NET. 我已经坚持了一段时间,并且对ASP.NET中的连接仍然很陌生。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

I think you need to add the ProviderName property to your SqlDataSource control, eg: 我认为您需要将ProviderName属性添加到SqlDataSource控件中,例如:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
 ConnectionString="<%$ ConnectionStrings:AccessConnectionString %>"
 ProviderName="<%$ ConnectionStrings:AccessConnectionString.ProviderName %>"
 SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"
 UpdateCommand="UPDATE [Categories] SET [CategoryName] = @CategoryName, [Description] = 
 @Description WHERE [CategoryID] = @original_CategoryID">

If you don't specify the provider, it defaults to the ADO.NET provider for Microsoft SQL Server which does not have a Provider keyword. 如果未指定提供程序,则默认为Microsoft SQL Server的ADO.NET提供程序,该提供程序没有Provider关键字。 ( http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx ) http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM