ConnectionString中未指定OLE DB提供程序';提供程序=SQLOLEDB;

本文关键字:程序 SQLOLEDB OLE ConnectionString 未指定 DB | 更新日期: 2023-09-27 17:59:13

我试图使用C#运行查询,遇到以下问题

ConnectionString中未指定OLE DB提供程序。例如,"Provider=SQLOLEDB;

我的代码

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"/>

有什么建议吗?

ConnectionString中未指定OLE DB提供程序';提供程序=SQLOLEDB;

尝试将其添加到连接字符串中

Provider=SQLNCLI10.1

事实的确如此;

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

使用SqlConnection而不是OleDbConnection