database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
ㆍCache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Cache Q&A 395 게시물 읽기
No. 395
[닷넷] Transaction 사용 예제
작성자
닷넷가이
작성일
2009-03-30 15:37ⓒ
2009-03-30 15:38ⓜ
조회수
6,163

.NET Managed Provider에서 트랜잭션 mode를 설정할 필요가 있을 때에는 다음과 같은 형태로 사용할 수 있다.


CacheTransaction Trans = CacheConnect.BeginTransaction(

);

Trans.Commit(); 혹은 Trans.Rollback();


다음은 트랜잭션을 사용하여 SSN(주민번호)의 유일성 오류시 트랜잭션을 rollback 하는 예제입니다. 참고로, C# 예제입니다.


  CacheTransaction Trans =

CacheConnect.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);

try {

string SQLtext = "INSERT into Sample.Person(Name, SSN) Values(?,?)";

CacheCommand Command = new CacheCommand(SQLtext, CacheConnect, Trans);

 

CacheParameter Name_param = new CacheParameter("name", CacheDbType.NVarChar);

Name_param.Value = "Rowe, Richard";

Command.Parameters.Add(Name_param);

 

CacheParameter SSN_param = new CacheParameter("ssn", CacheDbType.NVarChar);

SSN_param.Value = "070625-3081454";

Command.Parameters.Add(SSN_param);

 

int rows = Command.ExecuteNonQuery();

Trans.Commit();

Display.WriteLine("Added record for " + SSN_param.Value.ToString());

}

catch (Exception eInsert) {

Trans.Rollback();

WriteErrorMessage("TransFail", eInsert);

}

**트랜잭션 모드 설명

System.Data.IsolationLevel 에는 다음과 같은 모드 등이 있습니다.

ReadCommitted Shared locks are held while the data is being read to avoid dirty reads, but the data can be changed before the end of the transaction, resulting in non-repeatable reads or phantom data. 

ReadUncommitted A dirty read is possible, meaning that no shared locks are issued and no exclusive locks are honored. 

보다 자세한 내용은 MSDN 사이트 참조:


http://msdn2.microsoft.com/en-us/library/system.data.isolationlevel.aspx

[Top]
No.
제목
작성자
작성일
조회
398[웹-ZEN] Zen 소개
ZEN가이
2009-03-30
5099
397[보안] 개발자가 시스템관리포탈에서 테이블 보기
보안관
2009-03-30
5287
396[SQL]트랜잭션 테스트 방법
배영민
2009-03-30
4941
395[닷넷] Transaction 사용 예제
닷넷가이
2009-03-30
6163
394[툴소개]WinSQL 다운받기
배영민
2009-03-30
7319
393[닷넷] .NET Managed Provider이용 DataSet 활용 예제
배영민
2009-03-30
4837
392[웹-CSP]CSP에서 한글이 깨질 때..
배영민
2009-03-30
4754
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.052초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다