Ulong ul_num;
Int li_sysdir,li_dir1,li_dir2,li_dir3,li_dir4,li_dir5,li_app;
String ls_driver,ls_start,ls_location,ls_apppath,ls_dbpath,ls_odbcstr;
//获取操作系统的system目录,并保存到ls_location变量
li_sysdir = RegistryGet(″KYEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Setup″,″SysDir″,RegString!ls_location);
IF li_sysdir = -1 THEN
Messagebox(′错误′,′应用程序无法获取Windows的系统目录,系统将终止运行d,Stopsign!);
RETURN;
END IF
//判断Sybase SQL Anywhere6.0的驱动程序是否正确安装
ls_driver = ls_location+′\WOD60T.DLL′
ls_start = ls_location+′\dbeng60.EXE′
IF NOT (FileExists(ls_driver) AND FileExists(ls_start)) THEN
Messagebox(′错误′,′系统中没有安装SQL Anywhere 6.0的驱动程序,系统将终止运行d,StopSign!);
RETURN;
END IF
//设置ODBC\ODBCINST.INI\ODBC DRIVERS
li_sysdir=RegistrySet(′HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI\ODBCDRIVER′,′Sybase SQL Anywhere 6.0′,RegString!,′Installed′);
IF li_sysdir = -1 THEN
Messagebox(′错误′,′应用程序无法设置ODBC DRIVERS,系统将终止运行d,StopSign!);
RETURN;
END IF
//设置ODBC\ODBCINST.INI
li_dir1=RegistrySet(′HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI\Sybase SQL Anywhere 6.0′,′CPTimeout′,RegString!,′not pooled′)
li_dir2=RegistrySet(′HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI\Sybase SQL Anywhere 6.0′,′Driver′,RegString!,ls_driver)
li_dir3=RegistrySet(′HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI\Sybase SQL Anywhere 6.0′,′Setup′,RegString!,ls_driver)
IF li_dir1=-1 OR li_dir2=-1 OR li_dir3=-1 THEN
Messagebox(′错误′,′应用程序无法设置ODBCINST.INI,系统将终止运行d,StopSign!);
RETURN;
END IF
//设置ODBC DATA SOURCE(MyDataSource为数据源名)
li_sysdir=RegistrySet(′HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI\ODBC Data Sources′,′MyDataSource′,RegString!,′Sybase SQL Anywhere 6.0′);
IF li_sysdir=-1 THEN
Messagebox(′错误′,′应用程序无法设置ODBC DATA SOURCE,系统将终止运行d,StopSign!);
RETURN;
END IF
//获取应用程序的安装路径(MyApp为应用程序安装到用户计算机上后在注册表中注册的应用程序名,MyDatabase.db为应用程序的数据库名,与应用程序在同一目录下,MyDataSource为数据源名)
li_app=RegistryGet(″KYEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\MyApp″,″Path″,RegString!ls_apppath)
IF li_app=-1 THEN
Messagebox(′错误′,′应用程序无法获取程序安装路径名,系统将终止运行d,StopSign!);
RETURN
ELSE
ls_dbpath=ls_apppath+′MyDatabase.db′;
END IF
//设置ODBC.INI
li_dir1=RegistrySet(′HKEY_current_user\software\odbc\odbc.ini\MyDataSource′,′driver′,RegString!,ls_driver);
li_dir2=RegistrySet(′HKEY_current_user\software\odbc\odbc.ini\MyDataSource′,′start′,RegString!,ls_start);
li_dir3=RegistrySet(′HKEY_current_user\software\odbc\odbc.ini\MyDataSource′,′autostop′,RegString!,′yes′);
li_dir4=RegistrySet(′HKEY_current_user\software\odbc\odbc.ini\MyDataSource′,′DataBaseFile′,RegString!,ls_db_path);
li_dir5=RegistrySet(′HKEY_current_user\software\odbc\odbc.ini\MyDataSource′,′DataBaseName′,RegString!,′MyDatabase′);
IF li_dir1=-1 OR li_dir2=-1 OR li_dir3=-1 OR li_dir4=-1 OR li_dir5=-1 THEN
Messagebox(′错误′,′应用程序无法设置ODBC.INI,系统将终止运行!′,StopSign!);
RETURN
END IF
ls_odbcstr=′dsn=MyDataSource;databasename=MyDatabase;databasefile=′+ls_dbpath;
sqlca.dbms=′odbc′;
sqlca.databse=′MyDatabase′;
sqlca.dbparm=″connectstring=′ ″+ls_odbcstr+″;uid=dba;pwd=sql′ ″;
connect using sqlca;
open(w_frame);
[此贴子已经被作者于2007-7-28 13:00:12编辑过]