在PB中能否动态创建ODBC数据源,实现数据库的链接,最好给出具体的解释或步骤

volin 2001-07-27 10:26:27
...全文
149 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
volin 2001-08-15
结帖
回复
pb65 2001-07-27
来晚了
回复
dotnba 2001-07-27
学习!
回复
tanye 2001-07-27
// [PUBLIC] Function f_set_odbc in f_set_odbc ( string s_dsn, string db_name ) returns integer
//--------------------------------------------------------------------
// Description:通过给定的名称和数据库文件名注册ODBC
//--------------------------------------------------------------------
// Arguments:
//
// [value] string s_dsn
// <description>
// [value] string db_name
// <description>
//--------------------------------------------------------------------
// Returns: (INTEGER)
//--------------------------------------------------------------------
// Author: YX_ZHANG Date: June, 2001
//====================================================================
Int answer,answer1,answer2,answer3,answer4,answer5,answer6,answer7
int answer8,answer9,answer10,answer11,answer12,answer13,answer14,answer15
String ls_driver,ls_start,ls_location,ls_value,db_path,cur_dir

String ls_apppath = 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\'
String ls_odbc1 = 'HKEY_LOCAL_MACHINE\Software\ODBC\ODBCINST.INI\'
String ls_odbc2 = 'HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\'
String ls_odbc3 = 'HKEY_USERS\.DEFAULT\Software\ODBC\ODBC.INI\'

answer=RegistryGet(ls_apppath + "dbeng6.exe","Path",RegString!,ls_location)

//Function Uint GetDriveTypeA (String drive) Library "kernel32.dll"
cur_dir=Space(256)
//GetCurrentDirectoryA(256,cur_dir) //取当前目录
if answer=-1 then
ls_location=cur_dir
ls_driver=ls_location+'dbodbc6.dll'
ls_start=ls_location+'dbeng6.exe'
if not (FileExists(ls_driver) AND FileExists(ls_start)) THEN
Messagebox('错误',ls_location+'目录中没有安装dbeng6.exe和dbodbc6.dll文件!',StopSign!)
return -1
else
RegistrySet(ls_apppath + "dbeng6.exe","path",RegString!,ls_location)
RegistrySet(ls_apppath + "dbeng6.exe","",RegString!,ls_start)
end if
else
ls_driver=ls_location+'dbodbc6.dll'
ls_start=ls_location+'dbeng6.exe'
if not (FileExists(ls_driver) AND FileExists(ls_start)) THEN
Messagebox('错误',ls_location+'目录中没有安装dbeng6.exe和dbodbc6.dll文件!',StopSign!)
return -1
end if
end if
//设置ODBC\ODBCINST.INI\ODBC DRIVERS
answer=RegistryGet(ls_odbc1 + 'ODBC DRIVERS','Adaptive Server Anywhere 6.0',RegString!,ls_value)
if answer=-1 THEN
answer1=RegistrySet(ls_odbc1 + 'ODBC DRIVERS','Adaptive Server Anywhere 6.0',RegString!,'Installed')
answer2=RegistrySet(ls_odbc1 + 'Adaptive Server Anywhere 6.0','Driver',RegString!,ls_driver)
answer3=RegistrySet(ls_odbc1 + 'Adaptive Server Anywhere 6.0','Setup',RegString!,ls_driver)
IF answer1=-1 OR answer2=-1 OR answer3=-1 THEN
Messagebox('错误','应用程序无法设置ODBC DRIVERS,运行不能继续!',StopSign!)
RETURN -1
END IF
end if

//设置ODBC DATA SOURCE名称
answer=RegistryGet(ls_odbc2 + 'ODBC Data Sources',s_dsn,RegString!,ls_value)
if answer=-1 THEN
db_path=cur_dir+'\'+db_name+".db"
answer=RegistrySet(ls_odbc2 + 'ODBC Data Sources',s_dsn,RegString!,'Adaptive Server Anywhere 6.0')
answer1=RegistrySet(ls_odbc2 + s_dsn,'driver',RegString!,ls_driver)
answer2=RegistrySet(ls_odbc2 + s_dsn,'start',RegString!,ls_start+' -d -Q -c1024')
answer3=RegistrySet(ls_odbc2 + s_dsn,'autostop',RegString!,'yes')
answer4=RegistrySet(ls_odbc2 + s_dsn,'DataBaseFile',RegString!,db_path)
answer5=RegistrySet(ls_odbc2 + s_dsn,'DataBaseName',RegString!,db_name)
answer6=RegistrySet(ls_odbc2 + s_dsn,'uid',RegString!,"dba")
answer7=RegistrySet(ls_odbc2 + s_dsn,'pwd',RegString!,"sql")

answer8=RegistrySet(ls_odbc3 + s_dsn,"Driver", RegString!,ls_driver)
answer9=RegistrySet(ls_odbc3 + s_dsn,"uid", RegString!,"dba")
answer10=RegistrySet(ls_odbc3 + s_dsn,"pwd", RegString!,"sql")
answer11=RegistrySet(ls_odbc3 + s_dsn,"Start", RegString!,ls_start+' -d -Q -c1024')
answer12=RegistrySet(ls_odbc3 + s_dsn,"DatabaseFile", RegString!,db_path)
answer13=RegistrySet(ls_odbc3 + s_dsn,"DatabaseName", RegString!,db_name)
answer14=RegistrySet(ls_odbc3 + s_dsn,"AutoStop", RegString!, "yes")
answer15=RegistrySet(ls_odbc3 + "ODBC Data Sources",s_dsn, RegString!, "Adaptive Server Anywhere 6.0")
if answer=-1 or answer1=-1 or answer2=-1 or answer3=-1 or &
answer4=-1 or answer5=-1 or answer6=-1 or answer7=-1 or &
answer8=-1 or answer9=-1 or answer10=-1 or answer11=-1 or &
answer12=-1 or answer13=-1 or answer14=-1 or answer15=-1 THEN
Messagebox('错误','应用程序无法设置ODBC DATA SOURCE,运行不能继续!',StopSign!)
RETURN -1
end if

end if
return 0
回复
wangsw 2001-07-27
以前的贴子中有,你查查就会找到
回复
hzslx 2001-07-27
hehe
回复
qiuwuhen 2001-07-27
http://lin2000.myrice.com/

这里有例程,自己下载吧。
回复
相关推荐
发帖
数据库相关
创建于2007-09-28

734

社区成员

PowerBuilder 数据库相关
申请成为版主
帖子事件
创建了帖子
2001-07-27 10:26
社区公告
暂无公告