当前位置: 代码迷 >> PB >> 在PB中怎么动态注册SQLserver 2000的ODBC数据库连接
  详细解决方案

在PB中怎么动态注册SQLserver 2000的ODBC数据库连接

热度:103   发布时间:2016-04-29 08:10:50.0
在PB中如何动态注册SQLserver 2000的ODBC数据库连接
string ls_root,ls_dsnname,ls_root_dsn,ls_root_Engines,ls_dbfullname,ls_root_source
string as_path,ls_driver 
  ls_driver = "C:\windows\system32\odbcjt32.dll"
ls_root = "HKEY_LOCAL_MACHINE\software\odbc\odbc.ini"
ls_root_source = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
  //数据源名字为:"glxt_fsqtsc"
  ls_dsnname = "glxt_fsqtsc" 
ls_root_dsn = ls_root + "\" + ls_dsnname
ls_dbfullname = "fsqtsc"
  //
  RegistrySet(ls_root,ls_dsnname,regstring!,"")  
   
//注册数据源名称
RegistrySet(ls_root_source,ls_dsnname,regstring!,"SQL Server")
  //注册数据源描述
  RegistrySet(ls_root_dsn,"Description",regstring!,ls_dsnname)
  //注册数据库驱动程序
  RegistrySet(ls_root_dsn,"Driver",regstring!,ls_driver)
//注册数据库服务器  
RegistrySet(ls_root_dsn,"Server",regstring!,ls_dbfullname)
  //注册数据库访问用户  
RegistrySet(ls_root_dsn,"LastUser",regstring!,"sa")

不知道漏了那个值,连不上,郁闷,请指教!

------解决方案--------------------
参数依次为数据源名,服务器地址,数据库名
public function boolean of_regodbc (string as_src, string as_srv, string as_db);string ls_odbc='HKEY_CURRENT_USER\Software\ODBC\ODBC.INI'

return RegistrySet(ls_odbc + '\' + as_src,'Database',RegString!,as_db)=1 &
and RegistrySet(ls_odbc + '\' + as_src,'Driver',RegString!,'SQLSRV32.dll')=1 &
and RegistrySet(ls_odbc + '\' + as_src,'Server',RegString!,as_srv)=1 
end function

cjt一般用来连接桌面数据库页岛,上面的是用来连接sqlserver的
  相关解决方案