- UID
- 189936
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-11-5
- 最后登录
- 1970-1-1
|
发表于 2006-11-2 13:42:52
|
显示全部楼层
MDL可以连接数据库的,但是前提条件是数据源必须预先创建好,然后使用下列的代码就可以实现了:
/*----------------------------------------------------------------------+
| |
| @NAME:mdlDatabase_setLinkType |
| @AUTHOR: XXXX |
| @DATE: 2004-1-13 16:41 |
| @DESCRIPTION:设置数据库连接类型(1=ORACLE, 2=ODBC, 3,4=OLEDB) |
| @ALTERATION: null
| |
+----------------------------------------------------------------------*/
Private int mdlDatabase_setLinkType
(
int dbType, // 数据源类型: 1=ORACLE, 2=ODBC, 3,4=OLEDB
char* dbName // 数据源名称
)
{
char full_path[MAXFILELENGTH], ch[64];
int status;
mdlSystem_getCfgVar (full_path, "MSLOCAL", 64);
strcpy (full_path, mdlSystem_expandCfgVar (full_path));
strcat(full_path,"config\\database\\");
switch(dbType)
{
case 1: strcpy(ch,"oracle.cfg");
break;
case 2: strcpy(ch,"odbc.cfg");
break;
case 3: strcpy(ch,"sybase.cfg");
break;
case 4: strcpy(ch,"ris.cfg");
break;
default: break;
}
strcat (full_path, ch);
status = mdlSystem_processCfgVarFile (full_path, CFGVAR_LEVEL_USER);
if(status != SUCCESS) return ERROR;
status = mdlSystem_loadMdlProgram ("SERVER.MA", "SERVER", "FRONTEND");
if(status != SUCCESS) return ERROR;
if (dbType == 1)
status = mdlDB_processSQL ("connect support/support@T:DATASERV");
else
status = mdlDB_activeDatabase (dbName);
if(status != SUCCESS)
{
return ERROR;
}
return SUCCESS;
}
以上那段代码在odbc连接方式下测试是成功的,但是其他两种方式没有经过严格的测试,你可以参考一下 |
|