Microsoft.Practices.EnterpriseLibrary for .Net2.0使用中的问题(相关问题持续更新)

Microsoft.Practices.EnterpriseLibrary 2.0版本相对1.1版本有了很大的变化,很早前就下了1.1版,一直没在项目中用,看看gotDotNet,2.0版的CTP已经出了,下了个,用一下。。。。

Q:使用Microsoft.Practices.EnterpriseLibrary.Data,用默认的DatabaseFactory.CreateDatabase()方法创建对象实例时,调用的什么连接字符串?如何设置?
A:首先看看2.0的Microsoft.Practices.EnterpriseLibrary.Data的一些变化

Data Access Application Block

Improvements in the System.Data namespace have enabled us to simplify the architecture of the Data Access Application Block. The main changes are as follows:

         Internally, the application block now uses the new DbProviderFactory classes to create new database objects such as connections, commands and parameters.

         The DbCommandWrapper and derived classes have been removed from the design. This is because the new classes in the System.Data.Common namespace have largely replaced the functionality of the DbCommandWrapper class. Certain methods that were on the DbCommandWrapper class have been moved to the Database class.

         The block now uses System.Configuration to manage the database configuration information although the configuration data is structured in much the same way as it was in previous versions of Enterprise Library. It is likely that the final release will use the new built-in <configurationStrings> configuration section to store connection strings, rather than using its own configuration section. The block will still include its own configuration sections for advanced connection information such as Oracle package mapping.

         It is now much easier to use the Data Access Application Block without any configuration. Connection strings can be passed directly to the constructors of the various database types, such as SqlDatabase.

         Enterprise Library for .NET Framework 2.0 will not initially include support for IBM DB2 databases. This is because the new Data Access Application Block requires the use of ADO.NET 2.0-compliant managed providers, and none that support IBM DB2 databases are likely to be available in time for the final Enterprise Library release. The IBM DB2 databases may be supported in the future when ADO.NET 2.0 managed providers are available.

简单回到上面的问题,连接字符串的默认设置放在项目的配置文件中。如果是WinApp,那么配置文件就是“项目名.exe.config”(设计时可以设置App.config文件);如果是WebApp,那么配置文件是“web.config”。分别举例如下:
==========WinApp(App.config文件);========
<configuration>
 <configSections>
  <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
 </configSections>
 <connectionStrings>
  <add
   name="DataAccessQuickStart1"
   providerName="System.Data.SqlClient"
   connectionString="server=(local);database=EntLibQuickStarts;Integrated Security=true" />
 </connectionStrings>
 <dataConfiguration defaultDatabase="DataAccessQuickStart1"/>
</configuration>

==========WebApp(web.config文件);=======
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
  </configSections>
 <connectionStrings>
  <remove name="LocalSqlServer"/>
  <add name="LocalSqlServer" connectionString="Data Source=.;Integrated Security=True;Initial Catalog=Morning2" providerName="System.Data.SqlClient"/>
 </connectionStrings>

  <dataConfiguration defaultDatabase="LocalSqlServer"/>  <!--这一句给EnterpriseLibrary.Data的连接字符串用-->

  <system.web>
<!--省略-->
  </system.web>
 </location>
</configuration>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值