Microsoft.Practices.EnterpriseLibrary.Data.DLL,但未在用户代码中处理 [英] Microsoft.Practices.EnterpriseLibrary.Data.DLL but was not handled in user code

查看:65
本文介绍了Microsoft.Practices.EnterpriseLibrary.Data.DLL,但未在用户代码中处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索Google并使用企业库数据访问权限连接数据库。

Searched google and using Enterprise library data access to connect database.

仅使用 https://www.nuget.org/packages/EnterpriseLibrary.Data/

添加到项目后,我将配置设置如下,

After added to the project, I've set the configuration as follows,

     <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
    </configSections>
  <dataConfiguration defaultDatabase="dProvider" />
    <connectionStrings>
        <add name="dProvider" connectionString="server=local;Initial Catalog=n;uid=sa;pwd=pwd"
            providerName="System.Data.SqlClient" />
    </connectionStrings>

通过以下应用程序调用,

Called through the application like the following,

Database db;
            string sqlCommand;
            DbCommand dbCommand;

            db = DatabaseFactory.CreateDatabase("dProvider"); or DatabaseFactory.CreateDatabase();

运行应用程序后,出现以下异常,

After run the application, I got the following exception,

{"Database provider factory not set for the static DatabaseFactory. Set a provider factory invoking the DatabaseFactory.SetProviderFactory method or by specifying custom mappings by calling the DatabaseFactory.SetDatabases method."}

我犯了什么错误?

推荐答案

终于找到了答案。

我使用的是版本6,但在配置部分中,我像第5版一样提到了它。因此发生了错误。

I've used version 6, but here I've mentioned like version 5 in the configuration section. So the error has occurred.

我已像下面那样替换了配置部分,它工作得很好。 :-)。

I've replaced the configuration section like following, It worked perfectly in good way. :-). Thanks a lot for the helpers.

<configSections>
         <section name="dataConfiguration" 
      type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, 
            Microsoft.Practices.EnterpriseLibrary.Data"/>
    </configSections>

并使用DataBaseProviderFactory类创建实例。

and used DataBaseProviderFactory class to create instance.

DatabaseProviderFactory factory = new DatabaseProviderFactory();

            db = factory.Create("dProvider");

这篇关于Microsoft.Practices.EnterpriseLibrary.Data.DLL,但未在用户代码中处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆