请求的数据库ConnString没有在连接字符串中设置提供程序名称 [英] The requested database ConnString does not have provider name set in the connection string
问题描述
我的应用程序是用C#开发的,我使用Microsoft.Practices.EnterpriseLibrary.Data访问MS Access数据库
当我尝试创建数据库连接时得到以下错误。
请求的数据库ConnString没有在连接字符串中设置提供者名称。
我在做什么错了?
我的代码:
My application was developed in C# and I am using Microsoft.Practices.EnterpriseLibrary.Data to access an MS Access database
when I try to create the database connection get the error below.
"The requested database ConnString does not have provider name set in the connection string."
What am I doing wrong?
My code:
Database db;
DbCommand cmd = null;
db = DatabaseFactory.CreateDatabase("ConnString");
App.config上的
:
on App.config:
<configuration>
<connectionStrings>
<add name="ConnString> connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DataBase\CDL.accdb ;Persist Security Info=False"/>
</connectionStrings>
</configuration>
推荐答案
您需要providerName
属性您的connectionString
,应设置为.NET Framework数据提供程序的名称。由于您使用的是Access数据库,因此您可能需要OLEDB提供程序:
You need aproviderName
attribute on yourconnectionString
, which should be set to the name of a .NET Framework data provider. Since you're using an Access database, you probably want the OLEDB provider:
<connectionStrings>
<add
name="ConnString"
providerName="System.Data.OleDb"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DataBase\CDL.accdb;Persist Security Info=False"
/>
</connectionStrings>
连接字符串和配置文件 [ ^ ]
不要硬编码您的DataProviders [ ^ ]
按照SaschaLefèvre和Richard Deeming的建议,我改变了App.Config:
Following the suggestions of Sascha Lefèvre and Richard Deeming, I changed the App.Config for:
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"/>
</configSections>
<dataConfiguration defaultDatabase="ConnString"/>
<connectionStrings>
<add name="ConnString" providerName="System.Data.OleDb" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DataBase\CDL.accdb ;Persist Security Info=False" />
</connectionStrings>
</configuration>
<connectionStrings>
<add name="Connection_String" connectionString="Data Source=MYPC;Initial Catalog=dbtest;Persist Security Info=True;User ID=sa;Password=abc_123456" providerName="System.Data.SqlClient" />
</connectionStrings>
看起来像你的小姐一些道具。确保添加providerName。
Just looks like your missing some props. Make sure you add providerName.
这篇关于请求的数据库ConnString没有在连接字符串中设置提供程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!