功能:1 pb6.5下自动注册odbc数据源;
2 自动获取程序或数据库目录;
3 不安装Sql anywhere 7.0 直连
//获取程序所在目录
String ls_curdir
ls_curdir=Space(256)
//为字符缓冲区开辟内存空间
GetCurrentDirectoryA(256,ls_curdir)
ulong ul_num
Int Answer,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,ansApp
string ls_driver,ls_start,ls_location,apppath,db_path,db_name,ODBCStr,ds_name,ls_dbpath
//设置Adaptive Server Anywhere 7.0的驱动程序路径
ls_Location =ls_curdir
ls_dbpath=ls_curdir+"/data/yingxiao.db"
//判断Adaptive Server Anywhere 7.0的驱动程序是否正确安装
ls_Driver=ls_Location+"/dbodbc7.dll"
ls_Start=ls_Location+"/dbeng7.exe"
//IF Not (FileExists(ls_Driver) AND FileExists(ls_Start)) Then
//MessageBox("错误!","系统中没有安装Adaptive Server Anywhere 7.0"+&
//"的驱动程序,系统将终止运行!",StopSign!)
//Return
//End IF
//设置ODBC/ODBCINST.INI/ODBC DRIVERS
Answer=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST.INI"+&
"/ODBC Drivers","Adaptive Server Anywhere 7.0", RegString!, "Installed")
IF Answer = -1 Then
MessageBox("错误!","应用程序无法设置ODBC/ODBCINST.INI/"+&
"ODBC DRIVERS,系统将终止运行",Information!)
Return
End if
//设置ODBC/ODBCINST.INI/
Answer1=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST."+&
"Adaptive Server Anywhere 7.0", "CPTimeout", RegString!, "not pooled")
Answer2=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST."+&
"INI/Adaptive Server Anywhere 7.0", "Driver", RegString!,ls_Driver)
Answer3=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST."+&
"INI/Adaptive Server Anywhere 7.0", "Setup", RegString!,ls_Driver)
IF Answer1 = -1 OR Answer2 = -1 OR Answer3 = -1 Then
MessageBox("错误!","应用程序无法设置ODBC/ODBCINST.INI,"+&
"系统将终止运行!",Information!)//程序中不折行
Return
End if
db_path = ""+ls_dbpath+""//设置数据库路径及文件名
db_name = "yingxiao" //设置数据库名称
ds_name = "yingxiao" //设置ODBC数据源名
//设置ODBC DATA SOURCE名称
Answer=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
"ODBC Data Sources", ds_name, RegString!, "Adaptive Server Anywhere 7.0")
Answer1=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"driver", Regstring!, ls_Driver)
Answer2=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"start", Regstring!, ls_Start)
Answer3=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"autostop", Regstring!, "yes")
Answer4=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"DataBaseFile", Regstring!, db_path)
Answer5=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"DataBaseName", Regstring!, db_name)
Answer6=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"PWD", Regstring!, "sql")
Answer7=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"UID", Regstring!, "dba")
IF Answer = -1 Then
MessageBox("错误!","应用程序无法设置ODBC DATA SOURCE名称,"+&
"系统将终止运行!",Information!) //程序中不折行
Return
End if
//设置ODBC.ini细节
Answer1=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+&
ds_name,"driver", Regstring!, ls_Driver)
Answer2=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+&
ds_name,"start", Regstring!, ls_Start)
Answer3=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+&
ds_name,"autostop", Regstring!, "yes")
Answer4=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+ds_name,&
"DataBaseFile", Regstring!, db_path)
Answer5=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+ds_name,&
"DataBaseName", Regstring!, db_name)
Answer6=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+ds_name,&
"PWD", Regstring!, "sql")
Answer7=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+ds_name,&
"UID", Regstring!, "dba")
IF Answer1 = -1 OR Answer2 = -1 OR Answer3 = -1 OR &
Answer4 = -1 OR Answer5 = -1 OR Answer6 = -1 OR Answer7 = -1 Then
MessageBox("错误!","应用程序无法设置ODBC.INI细节,"+&
"系统将终止运行!",Information!)
Return
End if
odbcstr='dsn=' + ds_name +';databasename=' + db_name + ';databasefile=' + db_path
SQLCA.DBMS="ODBC"
SQLCA.Database=db_name
SQLCA.DbParm="connectstring='" + odbcstr+";uid=dba;pwd=sql'"
open(w_splash)
//sleep(2)
connect using sqlca;
IF SQLCA.SQLCode = -1 THEN
MessageBox("数据库连接失败", "不能连接到数据库上,请检查。"+&
"~r~n出错的详细原因为:"+SQLCA.SQLErrText)
END IF
close(w_splash)
open(w_main) //打开应用程序主窗口
2 自动获取程序或数据库目录;
3 不安装Sql anywhere 7.0 直连
//获取程序所在目录
String ls_curdir
ls_curdir=Space(256)
//为字符缓冲区开辟内存空间
GetCurrentDirectoryA(256,ls_curdir)
ulong ul_num
Int Answer,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,ansApp
string ls_driver,ls_start,ls_location,apppath,db_path,db_name,ODBCStr,ds_name,ls_dbpath
//设置Adaptive Server Anywhere 7.0的驱动程序路径
ls_Location =ls_curdir
ls_dbpath=ls_curdir+"/data/yingxiao.db"
//判断Adaptive Server Anywhere 7.0的驱动程序是否正确安装
ls_Driver=ls_Location+"/dbodbc7.dll"
ls_Start=ls_Location+"/dbeng7.exe"
//IF Not (FileExists(ls_Driver) AND FileExists(ls_Start)) Then
//MessageBox("错误!","系统中没有安装Adaptive Server Anywhere 7.0"+&
//"的驱动程序,系统将终止运行!",StopSign!)
//Return
//End IF
//设置ODBC/ODBCINST.INI/ODBC DRIVERS
Answer=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST.INI"+&
"/ODBC Drivers","Adaptive Server Anywhere 7.0", RegString!, "Installed")
IF Answer = -1 Then
MessageBox("错误!","应用程序无法设置ODBC/ODBCINST.INI/"+&
"ODBC DRIVERS,系统将终止运行",Information!)
Return
End if
//设置ODBC/ODBCINST.INI/
Answer1=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST."+&
"Adaptive Server Anywhere 7.0", "CPTimeout", RegString!, "not pooled")
Answer2=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST."+&
"INI/Adaptive Server Anywhere 7.0", "Driver", RegString!,ls_Driver)
Answer3=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBCINST."+&
"INI/Adaptive Server Anywhere 7.0", "Setup", RegString!,ls_Driver)
IF Answer1 = -1 OR Answer2 = -1 OR Answer3 = -1 Then
MessageBox("错误!","应用程序无法设置ODBC/ODBCINST.INI,"+&
"系统将终止运行!",Information!)//程序中不折行
Return
End if
db_path = ""+ls_dbpath+""//设置数据库路径及文件名
db_name = "yingxiao" //设置数据库名称
ds_name = "yingxiao" //设置ODBC数据源名
//设置ODBC DATA SOURCE名称
Answer=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
"ODBC Data Sources", ds_name, RegString!, "Adaptive Server Anywhere 7.0")
Answer1=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"driver", Regstring!, ls_Driver)
Answer2=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"start", Regstring!, ls_Start)
Answer3=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"autostop", Regstring!, "yes")
Answer4=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"DataBaseFile", Regstring!, db_path)
Answer5=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"DataBaseName", Regstring!, db_name)
Answer6=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"PWD", Regstring!, "sql")
Answer7=RegistrySet("HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.ini/"+&
ds_name,"UID", Regstring!, "dba")
IF Answer = -1 Then
MessageBox("错误!","应用程序无法设置ODBC DATA SOURCE名称,"+&
"系统将终止运行!",Information!) //程序中不折行
Return
End if
//设置ODBC.ini细节
Answer1=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+&
ds_name,"driver", Regstring!, ls_Driver)
Answer2=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+&
ds_name,"start", Regstring!, ls_Start)
Answer3=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+&
ds_name,"autostop", Regstring!, "yes")
Answer4=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+ds_name,&
"DataBaseFile", Regstring!, db_path)
Answer5=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+ds_name,&
"DataBaseName", Regstring!, db_name)
Answer6=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+ds_name,&
"PWD", Regstring!, "sql")
Answer7=RegistrySet("HKEY_current_user/software/odbc/odbc.ini/"+ds_name,&
"UID", Regstring!, "dba")
IF Answer1 = -1 OR Answer2 = -1 OR Answer3 = -1 OR &
Answer4 = -1 OR Answer5 = -1 OR Answer6 = -1 OR Answer7 = -1 Then
MessageBox("错误!","应用程序无法设置ODBC.INI细节,"+&
"系统将终止运行!",Information!)
Return
End if
odbcstr='dsn=' + ds_name +';databasename=' + db_name + ';databasefile=' + db_path
SQLCA.DBMS="ODBC"
SQLCA.Database=db_name
SQLCA.DbParm="connectstring='" + odbcstr+";uid=dba;pwd=sql'"
open(w_splash)
//sleep(2)
connect using sqlca;
IF SQLCA.SQLCode = -1 THEN
MessageBox("数据库连接失败", "不能连接到数据库上,请检查。"+&
"~r~n出错的详细原因为:"+SQLCA.SQLErrText)
END IF
close(w_splash)
open(w_main) //打开应用程序主窗口