InstallShield高级应用--测试ORACL是否可连接

 实现原理:Oracle数据库连接是使用Microsoft ODBC for Oracle实现的。

通过Oracle连接数据库字符串,使用“ADODB.Connection“对象,连接到Access数据库,通过是否可连接成功判断

注意:当前电脑必包含ADODB.Connection个对象。

  

源码:

 

EXPORT prototype BOOL DB_CheckOraclerCon(BYREF STRING,BYREF STRING,BYREF STRING,BYREF STRING);
//Driver={Microsoft ODBC for Oracle};Server=myServerAddress;Uid=myUsername;Pwd=myPassword;
//Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServer.world;Uid=myUsername;Pwd=myPassword;
//============================================================//
//function : DB_CheckOraclerCon //
// //
//purpose: 测试ORACL是否可连接 //
// //
//Argment: svServerName-Oracle连接服务名称 //
// svUserName-登录帐号 //
// svUserPassword-登录密码 //
//return: TRUE -连接成功 FALSE - 连接失败 //
//Remark: 本验证使用 Microsoft ODBC for Oracle 验证 //
//============================================================//
function BOOL DB_CheckOraclerCon(svServerName,svUserName,svUserPassword,szError)
OBJECT pADOConnObj, pADORecordSetObj,pDBConObj;
STRING szADOConnObjID, szADORecordSetObjID, szConnString, szSQL,svDriver;
BOOL bExists;
begin
svDriver = "Microsoft ODBC for Oracle";
bExists = FALSE;
try
// Create ADO Connection Object to connect to the SQL server
szADOConnObjID = "ADODB.Connection";
set pADOConnObj = CreateObject(szADOConnObjID);

// Create the Oracle string to complete the connection
szConnString = "driver={" + svDriver + "};";
szConnString = szConnString + "server=" + svServerName + ";";
szConnString = szConnString + "uid=" + svUserName + ";";
szConnString = szConnString + "pwd=" + svUserPassword + ";";
//szConnString = szConnString + "database=master";

// Open the ADO Connection
pADOConnObj.Open(szConnString);
bExists = TRUE;
catch
Sprintf(szError,"Error:Number:%d;",Err.Number);
szError = szError +"Desc:"+Err.Description;
bExists = FALSE;
//Clean up
set pADOConnObj = NOTHING;
endcatch;
set pADOConnObj = NOTHING;
return bExists;
end;

posted @ 2012-05-11 11:08  ☆会飞的鱼☆  阅读(619)  评论(0编辑  收藏  举报