本文介绍了访问数据库时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."}

推荐答案

<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中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 09:37