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

비밀번호

댓글 작성자
 




... 16  17  18  19  [20]  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13441정성태11/12/202310829닷넷: 2159. C# - ASP.NET Core 프로젝트에서 서버 Socket을 직접 생성하는 방법파일 다운로드1
13440정성태11/11/20239679Windows: 253. 소켓 Listen 시 방화벽의 Public/Private 제어 기능이 비활성화된 경우
13439정성태11/10/202311582닷넷: 2158. C# - 소켓 포트를 미리 시스템에 등록/예약해 사용하는 방법(Port Exclusion Ranges)파일 다운로드1
13438정성태11/9/202311100닷넷: 2157. C# - WinRT 기능을 이용해 윈도우에서 실행 중인 Media App 제어
13437정성태11/8/202311310닷넷: 2156. .NET 7 이상의 콘솔 프로그램을 (dockerfile 없이) 로컬 docker에 배포하는 방법
13436정성태11/7/202311415닷넷: 2155. C# - .NET 8 런타임부터 (Reflection 없이) 특성을 이용해 public이 아닌 멤버 호출 가능
13435정성태11/6/202310641닷넷: 2154. C# - 네이티브 자원을 포함한 관리 개체(예: 스레드)의 GC 정리
13434정성태11/1/202310700스크립트: 62. 파이썬 - class의 정적 함수를 동적으로 교체
13433정성태11/1/20239470스크립트: 61. 파이썬 - 함수 오버로딩 미지원
13432정성태10/31/202310267오류 유형: 878. 탐색기의 WSL 디렉터리 접근 시 "Attempt to access invalid address." 오류 발생
13431정성태10/31/202310787스크립트: 60. 파이썬 - 비동기 FastAPI 앱을 gunicorn으로 호스팅
13430정성태10/30/202310987닷넷: 2153. C# - 사용자가 빌드한 ICU dll 파일을 사용하는 방법
13429정성태10/27/202311148닷넷: 2152. Win32 Interop - C/C++ DLL로부터 이중 포인터 버퍼를 C#으로 받는 예제파일 다운로드1
13428정성태10/25/202311344닷넷: 2151. C# 12 - ref readonly 매개변수
13427정성태10/18/202310776닷넷: 2150. C# 12 - 정적 문맥에서 인스턴스 멤버에 대한 nameof 접근 허용(Allow nameof to always access instance members from static context)
13426정성태10/13/202311270스크립트: 59. 파이썬 - 비동기 호출 함수(run_until_complete, run_in_executor, create_task, run_in_threadpool)
13425정성태10/11/202311163닷넷: 2149. C# - PLinq의 Partitioner<T>를 이용한 사용자 정의 분할파일 다운로드1
13423정성태10/6/202311072스크립트: 58. 파이썬 - async/await 기본 사용법
13422정성태10/5/202310789닷넷: 2148. C# - async 유무에 따른 awaitable 메서드의 병렬 및 예외 처리 [1]
13421정성태10/4/202311056닷넷: 2147. C# - 비동기 메서드의 async 예약어 유무에 따른 차이
13420정성태9/26/202319333스크립트: 57. 파이썬 - UnboundLocalError: cannot access local variable '...' where it is not associated with a value
13419정성태9/25/202310924스크립트: 56. 파이썬 - RuntimeError: dictionary changed size during iteration
13418정성태9/25/202312519닷넷: 2146. C# - ConcurrentDictionary 자료 구조의 동기화 방식
13417정성태9/19/202311821닷넷: 2145. C# - 제네릭의 형식 매개변수에 속한 (매개변수를 가진) 생성자를 호출하는 방법
13416정성태9/19/202310418오류 유형: 877. redis-py - MISCONF Redis is configured to save RDB snapshots, ...
13415정성태9/18/202311857닷넷: 2144. C# 12 - 컬렉션 식(Collection Expressions) [2]
... 16  17  18  19  [20]  21  22  23  24  25  26  27  28  29  30  ...