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

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  [113]  114  115  116  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11099정성태11/7/201630678.NET Framework: 620. C#에서 C/C++ 함수로 콜백 함수를 전달하는 예제 코드파일 다운로드1
11098정성태11/7/201620024오류 유형: 368. 빌드 이벤트에서 robocopy 사용 시 $(TargetDir) 매크로를 지정하는 경우 오류 발생
11097정성태11/7/201622945오류 유형: 367. go install: no install location for directory [...경로...] outside GOPATH
11096정성태11/6/201626753디버깅 기술: 83. PDB 파일을 수동으로 다운로드하는 방법
11095정성태11/6/201623029.NET Framework: 619. C# - Cognitive Services 중의 하나인 Face API를 사용해 얼굴 인식 및 흐림(blur) 효과 적용 [1]파일 다운로드1
11094정성태11/5/201624640VC++: 105. Visual Studio 2013/2015 - Ceemple OpenCV 확장을 이용한 웹캠 영상 출력
11093정성태11/4/201624553웹: 34. Edge 브라우저도 지원하는 클립보드 복사를 위한 자바스크립트 코드
11092정성태11/3/201631553.NET Framework: 618. C# - NAudio를 이용한 MP3 파일 재생 [5]파일 다운로드1
11091정성태11/3/201626315VC++: 104. std::call_once를 이용해 thread-safe한 Singleton 객체 생성파일 다운로드1
11090정성태11/1/201627770VC++: 103. C++ CreateTimerQueue, CreateTimerQueueTimer 예제 코드 [9]파일 다운로드1
11089정성태11/1/201626626디버깅 기술: 82. Windows 10을 위한 Symbol(PDB) 파일 내려받는 방법 [2]
11088정성태11/1/201630707.NET Framework: 617. C# - AForge.NET을 이용한 MP4 동영상 파일 재생 [7]파일 다운로드1
11087정성태11/1/201625134.NET Framework: 616. AForge.Video.FFMPEG를 최신 버전의 ffmpeg 파일로 의존성을 변경하는 방법파일 다운로드1
11086정성태11/1/201618966오류 유형: 366. The Microsoft Passport Container service terminated with the following error: General access denied error
11085정성태10/27/201633309.NET Framework: 615. C# - AForge.NET을 이용한 웹캠 영상 출력 [2]파일 다운로드1
11084정성태10/26/201621386오류 유형: 365. The User Profile Service service failed to the sign-in.
11083정성태10/26/201627881Windows: 131. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선 순위 조정 기능 [1]
11082정성태10/26/201629804.NET Framework: 614. C# - DateTime.Ticks의 정밀도 [4]파일 다운로드1
11081정성태10/26/201620323오류 유형: 364. You need to fix your Microsoft Account for apps on your other devices to be able to launch apps and continue experiences on this device.
11080정성태10/24/201623483Windows: 130. Windows Server 2016 Nano 서버 설치 방법
11079정성태10/21/201620603Windows: 129. Windows Server 2016 설치 CD에 있는 Convert-WindowsImage.ps1 사용 방법 정리
11078정성태10/21/201621898Windows: 128. Windows Server 2016 Nano 서버 VHD 이미지 만드는 방법 - TP5 기준
11077정성태10/21/201620389오류 유형: 363. Active Directory 서버의 NETLOGON 서비스가 멈췄을 때 발생하는 문제
11076정성태10/21/201619976오류 유형: 362. 윈도우 백업 시 오류 - 0x80780040
11075정성태10/20/201620935Windows: 127. Convert-WindowsImage.ps1 사용 방법 정리
11074정성태10/20/201629241Windows: 126. Windows Server 2016 평가판을 정식 버전으로 라이선스 변경하는 방법
... 106  107  108  109  110  111  112  [113]  114  115  116  117  118  119  120  ...