使用Databasefactory.Createdatabase函数时出错 [英] Get Error When I Use Databasefactory.Createdatabase Function

查看:526
本文介绍了使用Databasefactory.Createdatabase函数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专家,



我正在做一个Asp.net 4.5项目,当我使用


Dear Experts,

I am Doing an Asp.net 4.5 project, and i got an error when i used the

DatabaseFactory.CreateDatabase("dataConfiguration");







这是配置代码..






Here is the Config code..

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

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







以下是以下错误代码




Here is the Below Error Code

Activation error occured while trying to get instance of type Database, key "dataConfiguration"







请帮帮我解决这个问题..





谢谢和问候,



Dileep ...




Please Help me to Solve this issue..


Thanks and Regards,

Dileep...

推荐答案

您的项目中的dll版本与EF dll不匹配,或者您需要更改.NET的版本打靶。至少,这是我用谷歌发现的,我对你的具体问题没有任何实际经验。
There's a mismatch in dll versions in your project for the EF dll, or you need to change the version of .NET you're targetting. At least, that's what I found out using google, I don't have any actual experience with your specific issue.


这就是我如何调用DataBaseFactory



数据库db = DatabaseFactory.CreateDatabase();



This is how I call DataBaseFactory

Database db = DatabaseFactory.CreateDatabase();

public static Database CreateDatabase();
   //
   // Summary:
   //     Method for invoking a specified Database service object. Reads service settings
   //     from the ConnectionSettings.config file.
   //
   // Parameters:
   //   name:
   //     configuration key for database service
   //
   // Returns:
   //     Database
   //
   // Exceptions:
   //   System.Configuration.ConfigurationException:
   //     instanceName is not defined in configuration.
   //     - or -
   //     An error exists in the configuration.
   //     - or -
   //     An error occured while reading the configuration.
   //
   //   System.Reflection.TargetInvocationException:
   //     The constructor being called throws an exception.


这篇关于使用Databasefactory.Createdatabase函数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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