Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An OLE DB Provider was not specified in the ConnectionString. 'Provider=SQLOLEDB;

i trying to run query using C#, i am getting the following problem

An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;

my code

string strConString = System.Configuration.ConfigurationManager.ConnectionStrings["WorkflowConnStr"].ConnectionString.ToString(); 
string sqlstr = "select * from table"        
OleDbConnection myConnection = new OleDbConnection(strConString);
try
     {myConnection.Open();}
catch (Exception err) 
     { System.Diagnostics.Debug.WriteLine(err.Message); }

OleDbCommand myCommand = new OleDbCommand(sqlstr, myConnection);
OleDbDataReader reader = myCommand.ExecuteReader();

web.config

<add name="WorkflowConnStr" connectionString="Data Source=Server;Initial Catalog=DBName;user id=usr;password=password" providerName="System.Data.OleDb.OleDbConnection"/>

any suggestion ?

like image 314
Noora Avatar asked Apr 21 '14 07:04

Noora


People also ask

What is Sqloledb provider?

The Microsoft OLE DB Provider for SQL Server, SQLOLEDB, allows ADO to access Microsoft SQL Server. The Microsoft OLE DB Provider for SQL Server (SQLOLEDB) remains deprecated and it is not recommended to use it for new development work.

What services does OLE DB provide?

OLE DB providers can be created to access such simple data stores as a text file and spreadsheet, through to such complex databases as Oracle, Microsoft SQL Server, Sybase ASE, and many others. It can also provide access to hierarchical data stores such as email systems.

What is ConnectionString property?

The ConnectionString property sets or returns the details used to create a connection to a data source. Note: You can not use both the Provider and File Name parameters.


2 Answers

Try adding this to your connection string,

Provider=SQLNCLI10.1

So it would be;

<add name="WorkflowConnStr" connectionString="Data Source=Server;Initial Catalog=DBName;user id=usr;password=password;Provider=SQLNCLI10.1" providerName="System.Data.OleDb.OleDbConnection"/>
like image 178
Mez Avatar answered Oct 12 '22 07:10

Mez


Use SqlConnection instead of OleDbConnection.

like image 33
Malek Tubaisaht Avatar answered Oct 12 '22 06:10

Malek Tubaisaht