Microsoft MVP성태의 닷넷 이야기
.NET Framework: 406. CoreLab - OraDirect .NET 사용법 [링크 복사], [링크+제목 복사],
조회: 19301
글쓴 사람
정성태 (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)
13625정성태5/14/2024199닷넷: 2262. C# - Exception Filter 조건(when)을 갖는 catch 절의 IL 구조
13624정성태5/12/2024455Phone: 14. C# - MAUI에서 MediaElement 사용파일 다운로드1
13623정성태5/11/2024591닷넷: 2261. C# - 구글 OAuth의 JWT (JSON Web Tokens) 해석파일 다운로드1
13622정성태5/10/2024636닷넷: 2260. C# - Google 로그인 연동 (ASP.NET 예제)파일 다운로드1
13621정성태5/10/2024605오류 유형: 902. IISExpress - Failed to register URL "..." for site "..." application "/". Error description: Cannot create a file when that file already exists. (0x800700b7)
13620정성태5/9/2024797VS.NET IDE: 190. Visual Studio가 node.exe를 경유해 Edge.exe를 띄우는 경우
13619정성태5/7/2024845닷넷: 2259. C# - decimal 저장소의 비트 구조파일 다운로드1
13618정성태5/6/20241031닷넷: 2258. C# - double (배정도 실수) 저장소의 비트 구조파일 다운로드1
13617정성태5/5/20241026닷넷: 2257. C# - float (단정도 실수) 저장소의 비트 구조파일 다운로드1
13616정성태5/3/2024972닷넷: 2256. ASP.NET Core 웹 사이트의 HTTP/HTTPS + Dual mode Socket (IPv4/IPv6) 지원 방법파일 다운로드1
13615정성태5/3/2024930닷넷: 2255. C# 배열을 Numpy ndarray 배열과 상호 변환
13614정성태5/2/2024860닷넷: 2254. C# - COM 인터페이스의 상속 시 중복으로 메서드를 선언
13613정성태5/1/2024890닷넷: 2253. C# - Video Capture 장치(Camera) 열거 및 지원 포맷 조회파일 다운로드1
13612정성태4/30/2024912오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file
13611정성태4/29/2024925닷넷: 2252. C# - GUID 타입 전용의 UnmanagedType.LPStruct - 두 번째 이야기파일 다운로드1
13610정성태4/28/2024994닷넷: 2251. C# - 제네릭 인자를 가진 타입을 생성하는 방법 - 두 번째 이야기
13609정성태4/27/20241033닷넷: 2250. PInvoke 호출 시 참조 타입(class)을 마샬링하는 [IN], [OUT] 특성파일 다운로드1
13608정성태4/26/20241106닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?파일 다운로드1
13607정성태4/25/20241111닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/20241074닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/20241077닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/20241061오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/20241129닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/20241067닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/20241091닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...