Keyword not supported: "provider". Opening SqlConnection

I do not know why this error, I tried everything. I want to connect my webForm to the .accdb database, and when I use with () {}, 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 { // ..... } } 
+12
source share
7 answers

Alexey Minkov is right. But here is more detailed, as you need more clarification.

Your web.config is fine. A line generated automatically by Visual Studio uses the correct setting. Instead, in your webform1 file, you need to do 2 things.

  • Add using System.Data.OleDb.OleDbConnection; to the beginning of the file and delete using System.Data.SqlConnection;

  • Change your webform1 code as follows:

     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 { } } 
+19
source

I know this is a somewhat old thread and already answered, but I am adding my solution for future use

I have a SQL Server 11.0 database, and I encountered an error when I tried to work with it in a SharePoint application, I did not try the other suggested answers, but I just deleted the "Provider" part (and reordered), so my connection string looked like this :

 Provider=SQLOLEDB.1;Password=DBPassword;Persist Security Info=True;User ID=sa;Initial Catalog=DBName;Data Source=DBServer 

Now it looks like this:

 Data Source=DBServer;Initial Catalog=DBName;Persist Security Info=True;User ID=sa;Password=DBPassword; 

And it worked just fine

+6
source

You should use System.Data.OleDb.OleDbConnection .

+5
source

I found an error here (and a similar one) while working in Visual Studio and passed the name of the connection manager as a parameter to the Script task to determine my connection string. Using the ConnectionString method results in a connection with more elements (or values ​​/ pairs) than expected (including the provider). The expected connection string in my case requires only a data source, source directory and built-in security.

There are two options for solving this problem. The first thing that didn't actually work for me, but hope this works for you, was to do the following:

 SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(Dts.Connections[connMgrName].ConnectionString); string connectionString = builder.DataSource + ";" + builder.InitialCatalog + ";" + builder.IntegratedSecurity; 

I hope this works for you because you solve the problem in a few lines of code. However, the option that worked for me was to recreate my connection string only by selecting the value / pairs needed for the database:

 string connectionString = Dts.Connections[connMgrName].ConnectionString; // ConnectionString will contain unsupported keywords like 'provider' connectionString = connectionString.Trim(';'); // Remove the trailing semicolon so that when we perform the split in the following line, there are no index errors. var connStrDictionary = connectionString.Split(';').Select(x => x.Split('=')).ToDictionary(x => x[0], x => x[1]); // Here we get each value-pair from connection string by splitting by ';', then splitting each element by '=' and adding the pair to a Dictionary. try { connectionString = "Data Source=" + connStrDictionary["Data Source"] + ";Initial Catalog=" + connStrDictionary["Initial Catalog"] + ";Integrated Security=" + connStrDictionary["Integrated Security"]; // Build the actual connection string to be used. } catch(KeyNotFoundException) { Console.WriteLine("\t\tNot able to build the connection string due to invalid keyword used. Existing keywords and their values:"); foreach( KeyValuePair<string, string> kvp in connStrDictionary) { Console.WriteLine("\t\t\tKey = '{0}', Value = '{1}'", kvp.Key, kvp.Value); } } 

Hope this helps. Good luck

0
source

Well, I know that this is quite old, and I know that the answer was right in front of my face all the time, but I would like to emphasize that one parameter that messed me up because it was missing was providerName="System.Data.OleDb" . Just in case, if someone else looks at it as stupidly as I do.

0
source

I read all the above, I tried everything and still gives me this error? Am I trying to connect SQL Server to Visual Studio 2019 to display a grid data table? Thanks !

This is mistake

-1
source

Source: https://habr.com/ru/post/979359/


All Articles