Home > database >  [with] pb run every time the data source to select the data source
[with] pb run every time the data source to select the data source

Time:10-06

I was using a pb9.0 asa8.0
For example, I create a new application, new function in the application of f_regdatasource () is an automatic selection function of data source,
There are three parameters (the database name, username, password), built in the application of open event, but why is it that every time I ordered after the run, or jump out of the selected data source
Windows let me your choice? The master can help me with? Thank you
The content of the following is f_regdatasource () function
The integer li_rc, li_filenum
String ls_dir ls_dbfile, ls_datasource ls_dbname, ls_config
Boolean lb_exist
Ls_datasource=as_dbname
Ls_dbname=as_dbname
Ls_dir=GetCurrentdirectory ()
Ls_dbfile=ls_dir + '\' + ls_dbname + 'db'
Ls_config=ls_dir + "\ config ini"
Boolean lb_exeist
Lb_exist=FileExists (ls_dbfile)
If not lb_exist then
Messagebox (" prompt ", "in the current directory does not exist:" + ls_dbname + "db")
The halt
End the if
Lb_exist=FileExists (ls_config)
//whether the configuration file is
If lb_exist then
Li_rc=profileint (" config. Ini ", "start", "first", 0)
//if there is access to configuration files of the start of the first key
//if the key does not exist the assignment of 0
The else
Li_FileNum=FileOpen (ls_config LineMode! The Write! , Shared! , Append!)
FileWrite (li_FileNum, "[start] ~ r ~ n first=1")
Li_rc=1
//if there is no, then according to certain format to create a configuration file
End the if
If li_rc=1 then
//read the configuration file for the first time

If RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+" 8.0 "the Adaptive Server Anywhere," Driver ", RegString! , "dbodbc8. DLL)=1 then"
Messagebox (" prompt ", "data source registered success!" )
End the if
//register data
The else
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+" 8.0 "the Adaptive Server Anywhere," Driver ", RegString! , "dbodbc8. DLL")
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ ODBC Data Sources ", ls_datasource, RegString! 8.0 ", "the Adaptive Server Anywhere)
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+ ls_datasource," Drive ", RegString! , "dbodbc8. DLL")
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+ ls_datasource," PWD ", RegString! , "SQL")
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+ ls_datasource," DataFile RegString! , ls_dbfile)
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+ ls_datasource, AutoStop, RegString! , "Yes")
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+ ls_datasource," Integrated ", RegString! , "No")
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+ ls_datasource," DatabaseName ", RegString! , ls_dbname)
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+ ls_datasource," Debug ", RegString! , "No")
RegistrySet (" HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBCINST INI \ "+ ls_datasource," DisableMultiRowFetch RegString! , "No")
Setprofilestring (" config. Ini ", "start", "first" and "0")
//modify the configuration files of the initial value, and then no longer read the file
End the if
The SQLCA. DBMS="ODBC"
The SQLCA. The AutoCommit=False
The SQLCA. DBParm="ConnectString '" +" DSN="+ ls_datasource +"; UID="+ as_uid +"; The PWD="+ as_pwd +" '"
//connect to the database
Connect using the sqlca;
If the sqlca. Sqlcode & lt;> 0 then
If li_rc=0 then
Setprofilestring (" config. Ini ", "start", "first", "1")
Messagebox (" prompt ", "please reconnect")
The else
Messagebox (" with the database connection failure ", "the discovery of the error when connecting to the database,")
End the if
Return false
The else
Return true
Disconnect;
End the if

CodePudding user response:

You is a problem with the Settings, the program can't find!
Look at the parameters in the ODBC, and whether the Settings in your program!
  • Related