2007년 8월 27일 월요일

ODBC를 이용하여 DB2 사용시 SQL7008 에러 발생

[문제점]

DB2를 ODBC를 사용하여 연결 시 아래와 같은 에러가 발생됨

(Error originState HY000, Error [IBM][iSeries Access ODBC 드라이버]

[DB2 UDB]SQL7008 - SFPFMKD in SFALIB not valid for operation.)

[원인 분석]

 

에러분석 :                                                                                                                  

SQL7008 에러가 발생하는 것은 서버의 DataBase(DB2)의 권한 이나 ODBC의 환경 설정에서 Transaction 권한이 없는 경우에 발생 할 수 있다. 이에 대한 설정 중 DB2에 대한 설정은 언급하지 않겠다.

이문서는 ODBC 설정에 대하여 언급하도록 하겠다.

 

해결방법 :                                                                                                                  

DB2는 네 종류의 분이(Isolation) 레벨을 갖는다. ODBC Client의 설정을 통해 최적의 isolation level을 설정 할 수 있다.

è  Isolation level dirty ready, phantom reads 그리고 non-repeatable reads 와 같은 데이터 무결성 문제에 대해 어떻게 데이터를 보호하고 처리할 것인지를 결정하는 방법이다.

Default 값으로 Read uncommitted(*CHG) 로 설정이 되어 있다. 자세한 내용은 아래 동시성(Concurrency)를 참고하기 바란다.

이를 해결하기 위해 ODBC 설정에서 Commit ModeCommit Immediate(*NONE)을 선택한다.

ODBC DataSource 관리 è System DSN è 등록정보 è Server è 고급(확장) è Commit Mode 설정

참고자료 :                                                                                                                  

 

동시성(Concurrency)의 관리

다수의 동시 사용자들을 갖는다면, 그들의 활동의 상호작용에 대해 관리할 필요가 있다. , 각각의 사용자들이 어느 정도로 독립적으로 활동하고 있는 지를 결정할 필요가 있다. 관리해야 할 대상은 독립(Independence)의 정도 또는 다른 사용자들로부터 한 사용자의 분리(Isolation)의 정도이다. DB2는 네 종류의 분리(Isolation) 레벨을 갖는 데, 매우 분리(Isolation)되는 레벨에서 분리(Isolation)되지 않는 레벨까지 기술하면 다음과 같다.

 

l  반복 읽기(Repeatable Read)란 마지막 확약시점이후부터 다음 확약시점까지 응용프로그램에 의해 액세스되는 모든 행들에 잠금(Lock)을 유지한다. 만약 응용프로그램이 동일한 행을 다시 읽으려고 한다면, 그 값은 변경될 수 없다. 이 분리(Isolation)의 효과는 한 응용프로그램이 다른 응용프로그램이나 다른 사용자들로부터 테이블의 변경을 가하지못하도록 할 경우에 적용될 수 있다. 결과적으로 전반적인 동시성(Concurrency)이 감소될수 있다.

 

l  읽기 안정성(Read Stability)이란 하나의 단위작업(Unit Of Work)이 완료될 때까지 응용프로그램에 의해 액세스되는 모든 조건에 합당하는 행들에 잠금(Lock)을 유지한다. 다른 응용프로그램에 의한 변경되는 행들은 그들 응용프로그램에 의해 변경되는 행들이 확약될 때까지 그 행들을 읽을 수 없다. 한 응용프로그램이 동일한 조회를 한번 이상 하게 되면, 새로운 행이나 변경된 행들을 읽을 수 있다.

 

l  커서 안정성(Cursor Stability)이란 커서가 그 행에 위치하는 동안에만 그 행에 잠금(Lock)을 유지한다. 커서가 한 행에서 다른 행으로 이동하면 잠금(Lock)이 풀린다. 그러나 데이터가 변경되면 데이터가 확약될 때까지 잠금을 유지해야 한다. 따라서 커서 안정성은 데이터를 읽을 경우에만 적용된다. 모든 변경된 데이터들은 COMMIT 또는 ROLLBACK이 수행될 때까지 잠금(Lock)을 유지한다.

 

l  미확약 읽기(Uncommitted Read)란 잠금(Locks)에 의한 대기없이 행들을 볼 수 있도록 한다. 이는 읽기전용 또는 SELECT문에서만 적용된다. 그 외의 작업에서만 커서 안정성과  같은 방식으로 수행된다. 분리(Isolation) 레벨을 사용하는 한 응용프로그램은 다른 응용프로그램에 의해 미확약된 변경값을 포함하는 모든 행을 읽을 수 있다. 이 분리(Isolation) 레벨을 사용하면 동시성 잠금(Concurrency Lock)을 위해 대기할 수 없기  때문에 전반적으로 성능을 향상시킬 수 있다.

 

분리(Isolation) 레벨은 사전 컴파일(PreCompile)시 또는 한 어플리케이션 프로그램이 데이터베이스에 바인드(Bind)될 때 지정될 수 있다. 만약 아무런 분리(Isolation) 레벨을 지정하지 않으면, 생략시값인 커서 안정성이 사용된다. 패키지에 사용된 분리(Isolation) 레벨을 보려면 제어센터의 객체트리내의 패키지 폴더를 선택한다.

 

 

 

첨부자료 :                                                                                                                  

[참고문서]

http://www-912.ibm.com/s_dir/slkbase.NSF/643d2723f2907f0b8625661300765a2a/31821151773d0613862569b200550644?OpenDocument

 

IBM Software Technical Document

__________________________________________________________________
Document Information
Document Information

Document Number:

21653409

Functional Area:

Client Access

Subfunctional Area:

ODBC

Sub-Subfunctional Area:

Configuration

OS/400 Release:

V4R5M0; V5R1M0; V5R2M0; V5R3M0; V5R4M0

Product:

CA/400 WIN 95 EXPRESS CLIENT (5769XE100)
IBM ISERIES CLIENT ACCESS EXP (5722XE100)

Product Release:

N/A



__________________________________________________________________

Document Title
iSeries Access ODBC: Commit Mode Data Source Setting, Isolation Level, and Autocommit

Document Description

Important Note: This document discusses Client Access for Microsoft® Windows® 95 and Windows NT®, Client Access Express, and IBM® iSeries™ Access products. These names essentially refer to the same product; however, the functionality and name changed over the last several releases. For the purposes of this document, the terms Client Access, Client Access Express, and iSeries Access may be used interchangeably. Where a difference is important, the version of the product is used to identify the differences.


The iSeries Access for Windows ODBC Datasource has an option for Commit mode. This is the default isolation level that will be used if an application does not specifically set it. An isolation level specified by the application always overrides the value set in the data source.

ODBC defines autocommit and isolation level as two different connection properties. Both properties are set at the connection level via the SQLSetConnectAttr API using the SQL_TXN_ISOLATION and SQL_AUTOCOMMIT parameters. iSeries Access provides a commit mode property because some applications allow the user/programmer to set autocommit off but they do not expose the isolation level property. For example, the Microsoft DAO and RDO object models allow a programmer to set autocommit off; however, they do not allow any direct changes to the isolation level.

In R450 and earlier of Client Access, the default isolation level for Client Access is a proprietary DB2/400 isolation level of *NONE. Setting autocommit off with the default isolation level of *NONE has no effect - *NONE is similar to autocommit yes, isolation level Read Uncommitted. In this case, commits and rollbacks have no effect. Applications such as these need to set the datasource to the desired isolation level. In the case of RDO, another option is for the programmer to retrieve the connection handle and call the SQLSetConnectionOption API directly.

In R510 and later, the default isolation level was changed to *CHG (read uncommitted). This change in behavior was made so the default behavior of iSeries Access for Windows better matches the default used by the other DB2 platforms. Note that this change may cause existing applications to encounter the following error:

SQL7008 return code 3 - &1 in &2 not valid for operation. The reason code is 3. Reason Code 3 -- &1 not journaled, or no authority to the journal.

To avoid this message, journal the target files or change the commit mode setting in the data source to *NONE.

Autocommit On
The default behavior of iSeries Access for Windows is to map SQL_AUTOCOMMIT_ON to DB2/400 isolation level *NONE. This is not strictly compliant with the ODBC specification. It offers the best performance with no journaling required. Note that dirty reads are possible regardless of the isolation used. Applications that call triggers or procedures (particularly nested procedures) using isolation levels other than *NONE may encounter unpredictable results.

The R530 release of iSeries Access for Windows adds a new connection keyword that allows for an autocommit on setting that complies to the SQL specification. The new keyword is trueautocommit. It can be used in the connect string or added to a data source. A value of 1 indicates that the driver should strictly adhere to the specification, that is, it will run autocommit under any isolation level. The active isolation level is used even when autocommit is on. The disadvantages of this setting are that all files must be journaled which might result in slower peformance. Large insert, update and delete operations in particular can be signifcantly slower.

The cwbodbcreg utility can be used to add the trueautocommit keyword to an existing datasource. The tool is included in iSeries Access for Windows. The syntax for the tool is:
cwbodbcreg <DSN Name> trueautocommit <value>

A value of 1 enables true autocommit.
A value of 0 (the default) results in autocommit being implemented using *NONE isolation level.


Isolation Level Mappings

The following table shows how ODBC isolation levels relate to the DB2 UDB for iSeries isolation levels.



Figure 1 shows the location of the commit mode setting in the iSeries Access for Windows data source configuration.




 

 

댓글 없음:

댓글 쓰기