C# – Keyword not supported: ‘provider’. Opening SqlConnection

asp.netc

I don't know why this error, I tried everything. I want to connect my webForm to the Database .accdb
and when I use using(){} I got this error "Keyword not supported: 'provider"
Here is the code:

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
   {
       // .....                            
   }              
}

Best Answer

Aleksey Mynkov has it right. But here is more detail since you are needing more clarification.

Your web.config is fine. The auto-generated Visual Studios connection string is using the right setup. Instead, on your webform1 file you need to do 2 things.

  1. Add using System.Data.OleDb.OleDbConnection; to the top of your file, and remove the using System.Data.SqlConnection;

  2. Change your webform1 code to be:

    private static string conDB = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
        using (OleDbConnection con = new OleDbConnection(connDB))  //here is the error
        {
        }
    }
    
Related Topic