简体   繁体   中英

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. I'm also using an SQLDataSource Control in the page, which is seen here:

 <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. Here's my Web.config file here:

<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. I've been stuck on this for awhile, and I'm still very new to connections in ASP.NET. Any help is greatly appreciated.

I think you need to add the ProviderName property to your SqlDataSource control, eg:

<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. ( http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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