#include //需要包含这个头文件
//安装 Visual Foxpro 的 ODBC 数据源, 如果数据源不存在,创建,否则为修改数据源参数
//Name 为数据源的名字(DSN), Type 为 "DBC" 或者 "DBF", Source 为文件名(Type为DBC)或者文件夹名(Type为DBF)
void ConfigVfpOdbc(char *Name, char *Type, char *Source)
{
char DsnBuffer[4096];
strcpy(DsnBuffer, "DSN=" ); strcat(DsnBuffer, Name ); strcat(DsnBuffer, "\r");
strcat(DsnBuffer, "SourceType="); strcat(DsnBuffer, Type ); strcat(DsnBuffer, "\r");
strcat(DsnBuffer, "SourceDB=" ); strcat(DsnBuffer, Source); strcat(DsnBuffer, "\r");
strcat(DsnBuffer, "\r" ); //end of DsnBuffer
for(int i=0; DsnBuffer[i]; i++)
if(DsnBuffer[i]=='\r')
DsnBuffer[i]=0;
if(!SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Visual FoxPro Driver\0", DsnBuffer))
throw Exception(AnsiString("不能安装 ODBC 数据源: ") + Name);
}
//安装 Interbase 6 的 ODBC 数据源,如果数据源不存在,创建,否则为修改参数
//Name 为数据源名, Source 为数据库名, User 为用户名, Pswd 为密码, Role 为角色名
void ConfigIB6Odbc(char *Name, char *Source, char *User, char *Pswd, char *Role) //Interbase 6.0 ODBC
{
char DsnBuffer[4096];
strcpy(DsnBuffer, "DSN=" ); strcat(DsnBuffer, Name ); strcat(DsnBuffer, "\r");
strcat(DsnBuffer, "DB=" ); strcat(DsnBuffer, Source); strcat(DsnBuffer, "\r");
strcat(DsnBuffer, "UID=" ); strcat(DsnBuffer, User ); strcat(DsnBuffer, "\r");
strcat(DsnBuffer, "PWD=" ); strcat(DsnBuffer, Pswd ); strcat(DsnBuffer, "\r");
strcat(DsnBuffer, "ROLE="); strcat(DsnBuffer, Role ); strcat(DsnBuffer, "\r");
strcat(DsnBuffer, "\r" ); //end of DsnBuffer
for(int i=0; DsnBuffer[i]; i++)
if(DsnBuffer[i]=='\r')
DsnBuffer[i]=0;
if(!SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Easysoft IB6 ODBC\0", DsnBuffer))
throw Exception(AnsiString("不能安装 ODBC 数据源: ") + Name);
}
--------------------next---------------------
阅读(1045) | 评论(0) | 转发(0) |