访问数据库时Enterprise Library 6.0中出错 [英] Error in Enterprise Library 6.0 when access data base

查看:146
本文介绍了访问数据库时Enterprise Library 6.0中出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



im使用Enterprise Library 6.0进行数据访问,即时下载并安装,但是当我用它进行CRUD操作时比通过例外:



{数据库提供程序工厂未设置为静态DatabaseFactory。设置提供程序工厂调用DatabaseFactory.SetProviderFactory方法或通过调用DatabaseFactory.SetDatabases方法指定自定义映射。}


i m using Enterprise Library 6.0 for data access, i m download it and installed, but when i used it for CRUD operation than it through exception like:

{"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."}

推荐答案

我遇到了同样的问题,下面的代码对我有用。



Web.config:

根据以下配置更改 dataConfiguration 部分:



I was facing the same problem, below code worked for me.

Web.config:
Change dataConfiguration section as per below configuration:

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





同时更改访问DatabaseFactory.CreateDatabase()的代码。



Also change the code where you are accessing the DatabaseFactory.CreateDatabase().

DatabaseProviderFactory factory = new DatabaseProviderFactory();
var db = factory.Create("ConnectionString");
var ds = new DataSet();
var cmd = db.GetStoredProcCommand("uspGetDetails");
db.AddInParameter(cmd, "@userName", DbType.String, "Developer");
ds = db .ExecuteDataSet(cmd);


这篇关于访问数据库时Enterprise Library 6.0中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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