Microsoft Enterprise Library June 2005--Data Access Application Block访问Oracle数据库(1)
前几日有幸拜读了Rickie Lee的《Microsoft patterns & practices Enterprise Library系列分析文章》(请参见http://rickie.cnblogs.com/archive/2005/02/21/104472.aspx)。赶紧去网站下载了Microsoft patterns & practices Enterprise Library,并安装使用。下面是我利用Enterprise Library实现访问oracle,并完成添加,删除,修改等数据库操作.
1.新建一个windows应用程序解决方案,使用Enteprise Library配置工具创建配置文件(这些在Rickie Lee的文章已经有详细描述,我就不多写了)。
这是我的配置文件
================App.config===================================
<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" 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" />
<includeTypes />
</enterpriselibrary.configurationSettings>
</configuration>
======================dataConfiguration.config========================
<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null">
<enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="Oracle Instance" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
<databaseTypes>
<databaseType name="Oracle Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null" />
</databaseTypes>
<instances>
<instance name="Oracle Instance" type="Oracle Server" connectionString="Oracle Connection String" />
</instances>
<connectionStrings>
<connectionString xsi:type="OracleConnectionStringData" name="Oracle Connection String">
<parameters>
<parameter name="pwd" value="zl" isSensitive="true" />
<parameter name="uid" value="zl" isSensitive="false" />
<parameter name="server" value="workserver" isSensitive="false" />
</parameters>
<packages />
</connectionString>
</connectionStrings>
</enterpriseLibrary.databaseSettings>
</xmlSerializerSection>
</dataConfiguration>
2.程序运行的主界面
3.程序代码如下:
//注意命名空间的引用
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Configuration;
4.存储过程代码如下:
create or replace procedure DeleteTest
(aId in varchar2)
is
begin
delete * from test where id=aid;
end;
create or replace procedure InsertTest
(aId in varchar2,aName in varchar2)
is
begin
insert into test(id,name) values(aid,aname);
end;
create or replace procedure UpdateTest
(aId in varchar2,aName in varchar2)
is
begin
update test set name=aName where id = aId;
end;