未在连接字符串中指定 OLE DB 提供程序。'提供者=SQLOLEDB;



我试图使用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"/>

有什么建议吗?

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

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

相关内容

最新更新