今天把 MS Enterprise Library DataAccess block成功搞定了,把哪個XML ,成功移置到Web Application
Web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="enterpriselibrary.configurationSettings" type="System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<enterpriselibrary.configurationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultSection="" applicationName="Application" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">
<configurationSections>
<configurationSection name="dataConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="dataConfiguration.config" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>
</configurationSections>
<keyAlgorithmStorageProvider xsi:nil="true" />
</enterpriselibrary.configurationSettings>
Common.cs
using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
/// <summary>
/// 使用MS Enterprise Library ,用SQL,返回DataSet
/// </summary>
/// <returns></returns>
public static DataSet SqlGetCustomer()
{
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "select top 10 CustomerID,ContactName,Address,City,Country,PostalCode from Customers";
DBCommandWrapper dbCommandWrapper = db.GetSqlStringCommandWrapper(sqlCommand);
DataSet Customer = db.ExecuteDataSet(CommandType.Text,sqlCommand);
return Customer;
}
/// <summary>
/// Use Proc return DataSet
/// (
/// Create Proc dbo.GetCustomer
/// AS
/// select top 10 CustomerID,ContactName,Address,City,Country,PostalCode from Northwind.dbo.Customers
/// Go
/// )
/// </summary>
/// <returns>DataSet</returns>
public static DataSet ProcGetCustomer()
{
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "GetCustomer";
DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper(sqlCommand);
// dbCommandWrapper.AddInParameter("@CategoryID", DbType.Int32, Category);
// DataSet that will hold the returned results
DataSet productsDataSet = null;
productsDataSet = db.ExecuteDataSet(dbCommandWrapper);
// Note: connection was closed by ExecuteDataSet method call
return productsDataSet;
}