VC 연결 oracle 데이터베이스

1323 단어 OacleVC
1. 라 이브 러 리 파일 을 가 져 오고 전역 연결 문자열 을 설정 합 니 다.
#import "C:\Program Files\Common Files\System\ado\msado60_Backcompat_i386.tlb" no_namespace rename("EOF","EndOfFile")

_ConnectionPtr pConn=NULL;	//     

2. 프로젝트 디 렉 터 리 에 SQL 새로 만 들 기connect. ini 파일, 입력
127.0.0.1 은 이 기기 가 다른 IP 에 연결 되면 이 주 소 를 직접 수정 하면 된다 는 것 을 말한다.
데이터베이스 연결
Provider=MSDAORA.1;Password=test;User ID=test;Data Source=127.0.0.1:1521/orcl;Persist Security Info=True

3. 데이터베이스 조회
if (!AfxOleInit())											//   OLE/COM 
	{
		AfxMessageBox(_T("OLE init Error"));
		return FALSE;
	}
	//         
	CStdioFile file; 
	file.Open(_T("SQL_Connect.ini"), CFile::modeRead);
	CString str=_T("");
	file.ReadString(str);
	file.Close();
	const _bstr_t strSRC = (_bstr_t)str;
	//const _bstr_t strSRC= "Provider=MSDAORA.1;Password=test;User ID=test;Data Source=localhost:1521/orcl;Persist Security Info=True";
	if (FAILED(pConn.CreateInstance("ADODB.Connection")))
	{
		AfxMessageBox(_T("Create Instance failed!"));
		exit(0);
	}
	try
	{
		pConn->Open(strSRC,"","",adModeUnknown);
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.Description());
		exit(0);
	}
	

좋은 웹페이지 즐겨찾기