国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

在 .NET中使用Oracle數(shù)據(jù)庫事務

2024-07-10 13:03:00
字體:
供稿:網(wǎng)友


    在本文中,您將了解到如何在 visual basic .net (vb.net) 和 visual c# .net (c#) 中使用數(shù)據(jù)庫事務。具體來講,您將系統(tǒng)學習數(shù)據(jù)庫事務、在 .net 程序中使用 oracletransaction 對象以及如何設置事務保存點。本文中引用的所有腳本和文件都在這里提供。本文假定您大體上熟悉 c# 和 vb.net 編程。

  所需軟件

  如果您要跟隨我們逐步完成本文中給出的示例,那么您需要安裝以下軟件:

  windows nt 4.0、windows 2000、windows xp professional 或 windows server 2003

  能夠訪問一個已安裝的 oracle 數(shù)據(jù)庫(oracle8i 版本 3 8.1.7 或更高版本)

  oracle 客戶機(版本 10.1.0.2.0 或更高版本)

  oracle net(版本 10.1.0.2.0 或更高版本)

  oracle data providers for .net(版本 10.1.0.2.0 或更高版本)

  microsoft .net framework(版本 1.0 或更高版本)

  microsoft .net 框架 sdk(版本 1.0 或更高版本)

  如果您打算使用企業(yè)服務事務或分布式事務來開發(fā)和運行應用程序,那么您還需要安裝 oracle services for microsoft transaction server(10.1.0.2.0 或更高版本)。

  您需要分別下載和安裝 .net 框架以及 sdk(先安裝框架)。您還需要下載和安裝 oracle 數(shù)據(jù)庫 10g,它包括 oracle data provider for .net (odp.net)。您可以選擇在不同計算機或同一計算機上安裝 odp.net 和數(shù)據(jù)庫服務器。

  注意:odp.net 驅(qū)動程序針對 oracle 數(shù)據(jù)庫訪問進行了優(yōu)化,因此可以獲得最佳性能,并且它們還支持 oracle 數(shù)據(jù)庫的豐富特性,如 bfile、blob、clob、xmltype 等。如果您正在開發(fā)基于 oracle 數(shù)據(jù)庫的 .net 應用程序,那么就特性和性能來講,odp.net 無疑是最佳的選擇。

  數(shù)據(jù)庫模式設置

  首先,您需要設置數(shù)據(jù)庫模式,在此我們使用一個簡化的 web 商店示例。您必須首先創(chuàng)建一個名為 store 的用戶并按以下方式將所需的權限授予該用戶(您必須首先以擁有 create user 權限的用戶身份登錄數(shù)據(jù)庫才能創(chuàng)建用戶):

  create user store identified by store;
  grant connect, resource to store;

  注意:您會在源代碼文件 db1.sql 中找到前兩個語句和該部分中出現(xiàn)的設置 store 模式的其他語句。

  接下的語句以 store 用戶身份進行連接:

  connect store/store;

  以下語句創(chuàng)建了所需的兩個數(shù)據(jù)庫表,名稱分別為 product_types 和 products:

  create table product_types (
  product_type_id integer
  constraint product_types_pk primary key,
  name varchar2(10) not null
  );

  create table products (
  product_id integer
  constraint products_pk primary key,
  product_type_id integer
  constraint products_fk_product_types
  references product_types(product_type_id),
  name varchar2(30) not null,
  description varchar2(50),
  price number(5, 2)
  );

  注意:如果您在一個不同的模式中為 store 用戶創(chuàng)建了這些數(shù)據(jù)庫表,那么您將需要修改示例配置文件(您稍后將看到)中的模式名稱。

  表 product_types 用于存儲示例在線商店可能庫存的產(chǎn)品類型的名稱,表 products 包含了所銷售產(chǎn)品的詳細信息。

  下面的 insert 語句為表 product_types 和 products 添加行:

  insert into product_types (
  product_type_id, name
  ) values (
  1, 'book'
  );
  insert into product_types (
  product_type_id, name
  ) values (
  2, 'dvd'
  );

  insert into products (
  product_id, product_type_id, name, description, price
  ) values (
  1, 1, 'modern science', 'a description of modern science', 19.95
  );
  insert into products (
  product_id, product_type_id, name, description, price
  ) values (
  2, 1, 'chemistry', 'introduction to chemistry', 30.00
  );
  insert into products (
  product_id, product_type_id, name, description, price
  ) values (
  3, 2, 'supernova', 'a star explodes', 25.99
  );
  insert into products (
  product_id, product_type_id, name, description, price
  ) values (
  4, 2, 'tank war', 'action movie about a future war', 13.95
  );

  commit;

  接下來,您將了解有關數(shù)據(jù)庫事務的內(nèi)容。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 安岳县| 杂多县| 安义县| 高雄县| 台中市| 广德县| 华池县| 东阳市| 盈江县| 共和县| 大关县| 修文县| 辽阳市| 娄烦县| 饶阳县| 铁岭县| 濮阳县| 额尔古纳市| 凤台县| 岚皋县| 朔州市| 鄱阳县| 罗定市| 晋州市| 泽州县| 承德市| 赣州市| 开封市| 休宁县| 崇州市| 永福县| 横峰县| 灵武市| 闽侯县| 德阳市| 彭阳县| 鸡泽县| 保定市| 和林格尔县| 浮梁县| 花垣县|