2009년 6월 11일 목요일

DSN List 얻기

//---------------------------------------------------------------------------
#include <vcl.h>
#include <sql.h>
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#pragma hdrstop
#pragma comment(lib, "odbc32.lib")
#include "regServerUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmRegisterDatabaseServer *frmRegisterDatabaseServer;
//---------------------------------------------------------------------------
__fastcall TfrmRegisterDatabaseServer::TfrmRegisterDatabaseServer(TComponent* Owner)
:
TForm(Owner)
{
}

//---------------------------------------------------------------------------
void __fastcall TfrmRegisterDatabaseServer::FormCreate(TObject *Sender)
{

//DSN 리스트 얻기
HENV hEnv;
char
tmpDSN[256];
SWORD tmpDSNLen = 255;
SWORD ResultLen;
UCHAR tmpDriver[256];
SWORD tmpDriverLen = 255;
SWORD ResultDescLen;
RETCODE ReturnCode = SQL_SUCCESS;
UnicodeString DSNList;

ReturnCode = ::SQLAllocEnv(&hEnv);
if
(SQL_SUCCESS == ReturnCode)
{

ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_FIRST, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);

while
(!ReturnCode)
{

// additional processing
DSNList = tmpDSN;
cbboxDSNList->AddItem(DSNList,NULL);
ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_NEXT, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);
};
}
}

//---------------------------------------------------------------------------

댓글 없음: