亲哥们,高手都在说把连接数据源写到程序里,初学者都在找,能给个例子吗
亲哥们,高手都在说把连接数据源写到程序里,菜鸟都在找,能给个例子吗?
MYSQL连PB 不用用户配置数据源 装了驱动运行直接连库 看高手们说能通过在程序里写代码或者写注册表实现
能给个例子吗,估计需要的人不少 我用完帮着传播一下 普及下基础知识吧!!
连上给分 (*^__^*) 嘻嘻……
------解决方案--------------------
[b]我自己寫的一個列子,建議先了解odbc的工作流程,以及系統注冊表屬性的意思![/b]
//用程式注冊 ODBC連接
integer li_ispass //是否執行函數成功
string ls_databasefile_current //當前系統注冊表中的databasefile屬性值
string ls_db_path //記錄當前target application所在的路徑
string ls_dsn //odbc別名
string ls_IsRegistry //是否重新注冊odbc
string ls_databaseFile //資料庫文件名稱
string ls_driverName //ODBC驅動程式名稱(系統回自動根據此名稱去找相關的驅動)
string ls_driver //ODBC驅動
string ls_uid //登陸帳號
string ls_pwd //登陸密碼
ls_db_path = GetCurrentDirectory() //獲得當前 target application所在的路徑
//從ini文件中讀取DSN
ls_IsRegistry = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','IsRegistry','yes')
ls_dsn = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','DatasourceName','billdb')
ls_databaseFile = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','DatabaseFile','billdb.db')
ls_driverName = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','DriverName','Adaptive Server Anywhere 7.0')
ls_driver = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','Driver','dbodbc7.dll')
ls_uid = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','Uid','dba')
ls_pwd = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','pwd','sql')
/*
以下用于從系統注冊表中的odbc數據源節中取出key值為billdb的value
billdb:指要從系統注冊表中取出值的key名稱,這里也表示ODBC名稱
RegString! 是registryRegStrin類型的枚舉,表示取出 以空字符結束的字符串
*/
if ls_IsRegistry = "yes" then //ini文件設定要重新注冊odbc時
//以下 先注冊odbc的名稱再注冊相關的屬性
if registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\odbc data sources", ls_dsn ,regstring!, ls_driverName) > 0 then
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"AutoStop",regstring!,"yes")
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"Driver",regstring!, ls_db_path + "\database\" + ls_driver)
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"pwd",regstring!, ls_pwd)
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"uid",regstring!, ls_uid)
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"Integrated",regstring!,"no")
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"DatabaseFile",regstring!, ls_db_path + "\database\" + ls_databaseFile)
else
messagebox('提示','注冊ODBC失敗!')
halt close
end if
end if
return ls_dsn
------解决方案--------------------
转一个access,应该都差不多
powerbuilder 自动注册odbc用户数据源(使用access数据库)2008-03-21 09:15/* powerbuilder开发程序一般需要在客户的"裸机"上注册odbc数据源(如果使用odbc数据源链接数据库)。此时不能让客户手动管理工具-->odbc数据源,这些操作应该对客户是透明的,所以需要程序中自动注册odbc数据源。本程序参考了网络上的一些自动注册odbc数据源的程序,自己观察了手动建立odbc数据源前后注册表表项的变化情况,然后利用查看和更改注册表的2个函数对注册表的相关条目进行操作,成功自动注册odbc数据源。程序给出了较清晰的注解,希望方便以后需要的朋友。
程序中可变的部分也相应以可变给出标记。*/
//自动注册odbc数据源(对access数据库)
string dsn //odbc数据源名
string database //access数据库
string currentPath //当前路径
string odbcDriver //odbc驱动
string myOdbc //程序目录中包含odbcjt32.dll驱动
currentPath = getCurrentDirectory()
if right(currentPath, 1) <> "\" then
currentPath = currentPath + "\"
end if
dsn = "autohardware" //数据源名可变
database = currentPath + "autoHardWare.mdb" //数据库文件可变
myOdbc = currentPath + "odbcjt32.dll" //提前把odbcjt32.dll放在程序目录中
/*此处可以添加一段程序:检查系统目录是否包含odbcjt32.dll,如果没有包含把
提前准备好的odbcjt32.dll拷贝到系统目录下
否则,程序认为用户的操作系统目录下包含odbcjt32.dll
MYSQL连PB 不用用户配置数据源 装了驱动运行直接连库 看高手们说能通过在程序里写代码或者写注册表实现
能给个例子吗,估计需要的人不少 我用完帮着传播一下 普及下基础知识吧!!
连上给分 (*^__^*) 嘻嘻……
------解决方案--------------------
[b]我自己寫的一個列子,建議先了解odbc的工作流程,以及系統注冊表屬性的意思![/b]
//用程式注冊 ODBC連接
integer li_ispass //是否執行函數成功
string ls_databasefile_current //當前系統注冊表中的databasefile屬性值
string ls_db_path //記錄當前target application所在的路徑
string ls_dsn //odbc別名
string ls_IsRegistry //是否重新注冊odbc
string ls_databaseFile //資料庫文件名稱
string ls_driverName //ODBC驅動程式名稱(系統回自動根據此名稱去找相關的驅動)
string ls_driver //ODBC驅動
string ls_uid //登陸帳號
string ls_pwd //登陸密碼
ls_db_path = GetCurrentDirectory() //獲得當前 target application所在的路徑
//從ini文件中讀取DSN
ls_IsRegistry = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','IsRegistry','yes')
ls_dsn = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','DatasourceName','billdb')
ls_databaseFile = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','DatabaseFile','billdb.db')
ls_driverName = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','DriverName','Adaptive Server Anywhere 7.0')
ls_driver = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','Driver','dbodbc7.dll')
ls_uid = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','Uid','dba')
ls_pwd = profilestring(ls_db_path + '\database\sys.ini','CreateODBC','pwd','sql')
/*
以下用于從系統注冊表中的odbc數據源節中取出key值為billdb的value
billdb:指要從系統注冊表中取出值的key名稱,這里也表示ODBC名稱
RegString! 是registryRegStrin類型的枚舉,表示取出 以空字符結束的字符串
*/
if ls_IsRegistry = "yes" then //ini文件設定要重新注冊odbc時
//以下 先注冊odbc的名稱再注冊相關的屬性
if registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\odbc data sources", ls_dsn ,regstring!, ls_driverName) > 0 then
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"AutoStop",regstring!,"yes")
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"Driver",regstring!, ls_db_path + "\database\" + ls_driver)
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"pwd",regstring!, ls_pwd)
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"uid",regstring!, ls_uid)
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"Integrated",regstring!,"no")
registryset("HKEY_CURRENT_USER\software\odbc\odbc.ini\" + ls_dsn ,"DatabaseFile",regstring!, ls_db_path + "\database\" + ls_databaseFile)
else
messagebox('提示','注冊ODBC失敗!')
halt close
end if
end if
return ls_dsn
------解决方案--------------------
转一个access,应该都差不多
powerbuilder 自动注册odbc用户数据源(使用access数据库)2008-03-21 09:15/* powerbuilder开发程序一般需要在客户的"裸机"上注册odbc数据源(如果使用odbc数据源链接数据库)。此时不能让客户手动管理工具-->odbc数据源,这些操作应该对客户是透明的,所以需要程序中自动注册odbc数据源。本程序参考了网络上的一些自动注册odbc数据源的程序,自己观察了手动建立odbc数据源前后注册表表项的变化情况,然后利用查看和更改注册表的2个函数对注册表的相关条目进行操作,成功自动注册odbc数据源。程序给出了较清晰的注解,希望方便以后需要的朋友。
程序中可变的部分也相应以可变给出标记。*/
//自动注册odbc数据源(对access数据库)
string dsn //odbc数据源名
string database //access数据库
string currentPath //当前路径
string odbcDriver //odbc驱动
string myOdbc //程序目录中包含odbcjt32.dll驱动
currentPath = getCurrentDirectory()
if right(currentPath, 1) <> "\" then
currentPath = currentPath + "\"
end if
dsn = "autohardware" //数据源名可变
database = currentPath + "autoHardWare.mdb" //数据库文件可变
myOdbc = currentPath + "odbcjt32.dll" //提前把odbcjt32.dll放在程序目录中
/*此处可以添加一段程序:检查系统目录是否包含odbcjt32.dll,如果没有包含把
提前准备好的odbcjt32.dll拷贝到系统目录下
否则,程序认为用户的操作系统目录下包含odbcjt32.dll