Microsoft MVP성태의 닷넷 이야기
.NET Framework: 406. CoreLab - OraDirect .NET 사용법 [링크 복사], [링크+제목 복사],
조회: 25608
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13768정성태10/15/20245416C/C++: 179. C++ - _O_WTEXT, _O_U16TEXT, _O_U8TEXT의 Unicode stream 모드파일 다운로드2
13767정성태10/14/20244791오류 유형: 929. bpftrace 수행 시 "ERROR: Could not resolve symbol: /proc/self/exe:BEGIN_trigger"
13766정성태10/14/20244565C/C++: 178. C++ - 파일에 대한 Text 모드의 "translated" 동작파일 다운로드1
13765정성태10/12/20245278오류 유형: 928. go build 시 "package maps is not in GOROOT" 오류
13764정성태10/11/20245643Linux: 85. Ubuntu - 원하는 golang 버전 설치
13763정성태10/11/20245003Linux: 84. WSL / Ubuntu 20.04 - bpftool 설치
13762정성태10/11/20245030Linux: 83. WSL / Ubuntu 22.04 - bpftool 설치
13761정성태10/11/20244931오류 유형: 927. WSL / Ubuntu - /usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
13760정성태10/11/20245465Linux: 82. Ubuntu - clang 최신(stable) 버전 설치
13759정성태10/10/20246384C/C++: 177. C++ - 자유 함수(free function) 및 주소 지정 가능한 함수(addressable function) [6]
13758정성태10/8/20245597오류 유형: 926. dotnet tools를 sudo로 실행하는 경우 command not found
13757정성태10/8/20245548닷넷: 2306. Linux - dotnet tool의 설치 디렉터리가 PATH 환경변수에 자동 등록이 되는 이유
13756정성태10/8/20245648오류 유형: 925. ssh로 docker 접근을 할 때 "... malformed HTTP status code ..." 오류 발생
13755정성태10/7/20246047닷넷: 2305. C# 13 - (9) 메서드 바인딩의 우선순위를 지정하는 OverloadResolutionPriority 특성 도입 (Overload resolution priority)파일 다운로드1
13754정성태10/4/20245589닷넷: 2304. C# 13 - (8) 부분 메서드 정의를 속성 및 인덱서에도 확대파일 다운로드1
13753정성태10/4/20245605Linux: 81. Linux - PATH 환경변수의 적용 규칙
13752정성태10/2/20246311닷넷: 2303. C# 13 - (7) ref struct의 interface 상속 및 제네릭 제약으로 사용 가능 [6]파일 다운로드1
13751정성태10/2/20245416C/C++: 176. C/C++ - ARM64로 포팅할 때 유의할 점
13750정성태10/1/20245312C/C++: 175. C++ - WinMain/wWinMain 호출 전의 CRT 초기화 단계
13749정성태9/30/20245551닷넷: 2302. C# - ssh-keygen으로 생성한 Private Key와 Public Key 연동파일 다운로드1
13748정성태9/29/20245749닷넷: 2301. C# - BigInteger 타입이 byte 배열로 직렬화하는 방식
13747정성태9/28/20245635닷넷: 2300. C# - OpenSSH의 공개키 파일에 대한 "BEGIN OPENSSH PUBLIC KEY" / "END OPENSSH PUBLIC KEY" PEM 포맷파일 다운로드1
13746정성태9/28/20245699오류 유형: 924. Python - LocalProtocolError("Illegal header value ...")
13745정성태9/28/20245567Linux: 80. 리눅스 - 실행 중인 프로세스 내부의 환경변수 설정을 구하는 방법 (lldb)
13744정성태9/27/20246009닷넷: 2299. C# - Windows Hello 사용자 인증 다이얼로그 표시하기파일 다운로드1
13743정성태9/26/20246444닷넷: 2298. C# - Console 프로젝트에서의 await 대상으로 Main 스레드 활용하는 방법 [1]
1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...