Microsoft MVP성태의 닷넷 이야기
.NET Framework: 406. CoreLab - OraDirect .NET 사용법 [링크 복사], [링크+제목 복사],
조회: 25707
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

CoreLab - OraDirect .NET 사용법

의외의 ADO.NET 데이터 제공자가 사용되는 경우가 있군요. ^^ 해외 고객사 중의 하나가 다음의 제품을 사용하는데요.

Download dotConnect for Oracle
; http://www.devart.com/dotconnect/oracle/download.html

아쉽게도 .NET 1.1용으로 만들어진 예전 사이트라서 "OraDirect .NET"을 사용하고 있었습니다.

OraDirect .NET for .NET Framework 1.x
- OraDirect .NET 4.75 Trial
; http://www.devart.com/dotconnect/oracle/oranet.exe

오라클 용은 무조건 ODP.NET을 사용하는 줄 알았는데 꼭 그런 것만은 아니군요. ^^




테스트를 위한 환경 구성을 해볼까요? ^^

OraDirect는 사실 ODP.NET에 대한 의존성은 그대로 가지고 있습니다. (그런데, 왜 굳이 OraDirect를 쓰는 걸까요? ^^) 따라서 ODP.NET을 설치해 주어야 합니다.

최신의 ODP.NET을 쓰는 것도 좋겠지만, 고객사가 .NET 1.1 사이트임을 감안할 때 ODP.NET도 그에 맞는 버전으로 가야 할 필요가 있었습니다. 그래서 아주 예전의 ODP.NET을 먼저 다운로드해서 설치해 주었습니다.

Oracle 10g ODAC 
; http://www.oracle.com/technetwork/database/windows/downloads/utilsoft-087491.html

이 버전은 아쉽게도 XCopy 설치가 안됩니다. 그래도 설치없이 동작시킬 수 있는 방법이 있긴 한데요. 다른 컴퓨터에서 ODAC101040.exe를 설치한 다음, 해당 폴더를 그대로 복사해 와서 그 경로를 레지스트리에 맞춰주면 됩니다.

다음은 ora10g_hom1.reg 파일로 저장해 둔 레지스트리 등록 파일입니다. 이 중에서 경로만 적절하게 수정해 주고 대상 PC에 등록해 주면 별도의 설치 과정없이 동작시킬 수 있습니다.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient10g_home1]
"ORACLE_HOME"="d:\\oracle\\product\\10.1.0\\Client_1"
"ORACLE_HOME_NAME"="OraClient10g_home1"
"ORACLE_GROUP_NAME"="Oracle - OraClient10g_home1"
"ORACLE_BUNDLE_NAME"="Enterprise"
"NLS_LANG"="KOREAN_KOREA.KO16MSWIN949"
"ORAMTS_CP_TRACE_LEVEL"="0"
"ORAMTS_CP_TRACE_DIR"="d:\\oracle\\product\\10.1.0\\Client_1\\oramts\\Trace"
"ORAMTS_CONN_POOL_TIMEOUT"="120"
"ORAMTS_SESS_TXNTIMETOLIVE"="120"
"ORAMTS_NET_CACHE_MAXFREE"="5"
"ORAMTS_NET_CACHE_TIMEOUT"="120000"
"ORAMTS_OSCREDS_MATCH_LEVEL"="OS_AUTH_LOGIN"
"OLEDB"="d:\\oracle\\product\\10.1.0\\Client_1\\oledb\\mesg"
"ORACLE_HOME_KEY"="SOFTWARE\\ORACLE\\KEY_OraClient10g_home1"
"OO4O"="d:\\oracle\\product\\10.1.0\\Client_1\\oo4o\\mesg"

[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient10g_home1\ODP.NET]
"TraceFileName"="C:\\ODPNET.trc"
"TraceLevel"="0"
"TraceOption"="0"
"StatementCacheSize"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient10g_home1\OLEDB]
"CacheType"="Memory"
"ChunkSize"="100"
"DistribTX"="1"
"FetchSize"="100"
"OSAuthent"="0"
"PLSQLRset"="0"
"PwdChgDlg"="1"
"SchRstLng"="10000"
"UserDefFn"="0"
"DisableRetClause"="1"
"VCharNull"="1"
"TraceCategory"="0"
"TraceFileName"="c:\\OraOLEDB.trc"
"TraceLevel"="0"
"TraceOption"="0"
"SPPrmDefVal"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient10g_home1\OO4O]
"CacheBlocks"="20"
"FetchLimit"="100"
"FetchSize"="4096"
"HelpFile"="d:\\oracle\\product\\10.1.0\\Client_1\\oo4o\\doc\\oracleo.hlp"
"PerBlock"="16"
"SliceSize"="256"
"TempFileDirectory"="c:\\temp"
"OO4O_HOME"="d:\\oracle\\product\\10.1.0\\Client_1\\oo4o"

ODP.NET 준비는 이것으로 끝입니다.

그다음, OraDirect의 경우 다행히 설치 과정은 필요없습니다. 파일을 풀어내기 위해 다른 컴퓨터에서 설치를 한후 다음의 2가지 파일만 복사해 오면 됩니다.

C:\Program Files\Devart\OraDirect.NET\CoreLab.Data.dll
C:\Program Files\Devart\OraDirect.NET\CoreLab.Oracle.dll

이 2개의 어셈블리 파일을 참조 추가하고 다음과 같이 코딩을 하면 됩니다.

using System;
using System.Diagnostics;
using CoreLab.Oracle;
using System.Data;
using System.IO;

string oradb = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testdb)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User Id=hr;Password=hr;";

using (CoreLab.Oracle.OracleConnection oraConnection = new CoreLab.Oracle.OracleConnection(oradb))
{
	oraConnection.Open();

	OracleCommand command = new OracleCommand();
	command.Connection = oraConnection;
	command.CommandText = "select department_name from departments";
	command.CommandType = CommandType.Text;
	using (OracleDataReader dr = command.ExecuteReader())
	{
		dr.Read();
	}

	Random random = new Random((int)DateTime.Now.Ticks);
	int regionId = random.Next(Int32.MaxValue);

	command = new OracleCommand();
	command.Connection = oraConnection;
	command.Parameters.Add(new OracleParameter("REGION_ID", regionId));
	command.Parameters.Add(new OracleParameter("REGION_NAME", "test"));

	// command.Parameters.Add(new OracleParameter("TEST", 1, 4, "test", ParameterDirection.Output))

	command.CommandText = "INSERT INTO Regions(REGION_ID, REGION_NAME) VALUES(:REGION_ID, :REGION_NAME)";
	command.ExecuteNonQuery();

	command = new OracleCommand();
	command.Connection = oraConnection;
	command.Parameters.Clear();
	command.Parameters.Add(new OracleParameter("REGION_ID", regionId));
	command.CommandText = "DELETE FROM Regions WHERE REGION_ID = :REGION_ID";
	command.ExecuteNonQuery();

	command.Parameters.Clear();
	command.CommandText = "SELECT COUNT(*) FROM Regions";
	object resultName = command.ExecuteScalar();
	//Debug.WriteLine(resultName);

	command = new OracleCommand();
	command.Connection = oraConnection;
	command.CommandText = "select department_name from departments";
	command.CommandType = CommandType.Text;
	OracleDataAdapter oda = new OracleDataAdapter(command);
	DataSet ds = new DataSet();
	oda.Fill(ds);
}

보시는 바와 같이 OraDirect.NET 사용법은 ODP.NET과 거의 다르지 않습니다.

참고로, 검색해 보니 다음의 글도 있군요. ^^

.NET에서 Oracle을 연결하는 Provider 3종류 연결 방법
; http://kirox.tistory.com/1

국내에서도 은근히 사용되는 것 같습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 6/28/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 151  152  153  154  155  156  157  158  159  160  161  162  163  [164]  165  ...
NoWriterDateCnt.TitleFile(s)
944정성태11/11/201031587VC++: 43. C++/CLI 컴파일 오류 - error C2872: 'IServiceProvider' : ambiguous symbol could be ...
943정성태11/8/201030719디버깅 기술: 30. windbg ".loadby sos" 명령어 [2]
942정성태11/7/201042314.NET Framework: 187. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 [7]파일 다운로드3
941정성태11/6/201025232.NET Framework: 186. windbg로 확인하는 .NET CLR LCG 메서드(DynamicMethod) [1]파일 다운로드1
940정성태11/6/201026077.NET Framework: 185. windbg로 확인하는 .NET CLR 메서드파일 다운로드1
939정성태10/24/201033051Windows: 51. RDP로 접속한 Windows Server 2008 R2 환경에서 Aero Glass 활성화 [1]
938정성태10/23/201024817디버깅 기술: 29. Windbg - Hyper-V 윈도우 7 원격 디버깅 구성 [1]
937정성태10/22/201030957DDK: 5. NT Legacy 드라이버: 프로세스(EXE) 생성/제거 모니터링 [3]파일 다운로드1
936정성태10/21/201029973DDK: 4. Device Driver 응용 프로그램의 빌드 스크립트 - 두 번째 이야기 [2]파일 다운로드1
935정성태10/17/201030570디버깅 기술: 28. Windbg - 윈도우 핸들 테이블 [3]
934정성태10/11/201033572디버깅 기술: 27. Windbg - Local Kernel Debug 모드 [2]
933정성태10/10/201025743.NET Framework: 184. 닷넷에서 호출 스택의 메서드에 대한 인자 값 확인이 가능할까? [2]파일 다운로드1
932정성태10/10/201028983DDK: 3. NT Legacy 드라이버를 이용하여 C#에서 Port 입출력파일 다운로드1
931정성태9/30/201023547오류 유형: 108. Net.Tcp Listener Adapter 서비스 시작 실패
930정성태9/30/201022845웹: 16. 윈도우 미디어 플레이어 - 일시 정지/시작을 스크립트에서 감지
929정성태9/17/201024097웹: 15. IE 9 - 작업 표시줄의 웹 사이트 바로가기 사용자 정의 - JumpLists [3]파일 다운로드1
928정성태9/16/201028251VC++: 42. 쓰기 전용 파일(예: 로그 파일)의 동기화 방법파일 다운로드1
927정성태9/14/201038130VC++: 41. UTF-8 포맷의 INI 파일에 대한 GetPrivateProfile... API 사용 불가 [2]
926정성태9/9/201027391Team Foundation Server: 41. 빌드 스크립트에 Code Coverage 추가 [1]파일 다운로드1
925정성태9/8/201031310Team Foundation Server: 40. Visual Studio 2010 - Code Coverage 결과를 외부 XML 파일로 출력하는 명령행 도구 제작 [1]파일 다운로드1
924정성태9/6/201021577개발 환경 구성: 88. SCVMM이 설치된 도메인에 참여하지 않은 Hyper-V 호스트 추가
923정성태9/5/201027559오류 유형: 107. SCVMM Agent 설치 오류 - Failed to configure the WS-Management service.
922정성태9/4/201036206오류 유형: 106. Hyper-V 가상 머신의 네트워크 끊김 현상
921정성태9/2/201030248DDK: 2. Device Driver 응용 프로그램의 빌드 스크립트 [2]파일 다운로드1
920정성태9/1/201034694오류 유형: 105. WMI - The RPC server is unavailable [2]
919정성태8/30/201040789DDK: 1. Visual Studio 2010 - Device Driver 제작- Hello World 예제 [3]파일 다운로드1
... 151  152  153  154  155  156  157  158  159  160  161  162  163  [164]  165  ...