使用Enterprise Library 3.1 中的數據訪問應用程序塊數據庫配置說明
就ACESS 、SQL2005以及Oracle進行分別說明和綜合配置說明
希望能給初了解的人有所幫助
SQL2005--------------------------------------------------------------
<?XML version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<dataConfiguration defaultDatabase="SQLCONN" />
<connectionStrings>
<add name="SQLCONN" connectionString="Data Source=PERRY;Initial Catalog=MuOnline;Persist Security Info=True;User ID=sa;PassWord=xIExiaopeng"
providerName="System.Data.SqlClIEnt" />
</connectionStrings>
</configuration>
創建實例:
Database db = DatabaseFactory.CreateDatabase("SQLCONN");
string sqlCommand = "Select * " + "From UserLogin";
DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
ACESS 2003--------------------------------------------------------------
<?XML version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<dataConfiguration defaultDatabase="ACESSCONN" />
<connectionStrings>
<add name="ACESSCONN" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:LifeEasyLifeEasyDataBaseLifeEasyDataBase.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
</configuration>
創建實例:
Database db = DatabaseFactory.CreateDatabase("ACESSCONN");
string sqlCommand = "Select * " + "From [User]";
DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
ACESS and SQL2005-------------------------------------------------------------------------------
<?XML version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<dataConfiguration defaultDatabase="AccessCONN" />
<connectionStrings>
<add name="AccessCONN" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:LifeEasyLifeEasyDataBaseLifeEasyDataBase.mdb"
providerName="System.Data.OleDb" />
<add name="SQLCONN" connectionString="Data Source=PERRY;Initial Catalog=MuOnline;Persist Security Info=True;User ID=sa;PassWord=xIExiaopeng"
providerName="System.Data.SqlClIEnt" />
</connectionStrings>
</configuration>