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:
Should be registered SQLANYWHERE you have any question,The following code to use without problems, save as uf_set_db. Import PBL use after SRF,
$PBExportHeader $uf_set_db. SRF
Global type uf_set_db from function_object
End type
Forward as
Global function integer uf_set_db (string as_dsn, string as_db_name, string as_db_parm)
End as
Global function integer uf_set_db (string as_dsn, string as_db_name, string as_db_parm);//registered SQLANYWHERE database
//here will SQLANYWHERE registered in this program in the operating system
//write here is the ASA8 PB9 registered, if you use other versions, you just need to change the eight to the corresponding version,
Int answer, answer1, answer2 answer3, answer4, answer5, answer6, answer7
String ls_driver ls_start, ls_location ls_value, db_path, ls_path
Ls_path=GetCurrentDirectory ()
If right (ls_path, 1)='\' then
Ls_path=mid (ls_path, 1, len (ls_path) - 1)
End the if
Ls_driver=ls_path + '\ dbodbc8 DLL'
Ls_start=ls_path + '\ dbeng8 exe'
If not (FileExists (ls_driver) AND FileExists (ls_start)) THEN
Messagebox (' mistakes', ls_path + 'directory not installed dbeng8. Exe and dbodbc8. DLL file! ', StopSign!)
Return 0
The else
RegistrySet (" HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ App Paths \ dbeng8 exe ", "path", RegString! , ls_path)
RegistrySet (" HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ App Paths \ dbeng8 exe ", "", RegString! , ls_start)
End the if
//set the ODBC \ ODBCINST INI \ ODBC DRIVERS
Answer1=RegistrySet (' HKEY_LOCAL_MACHINE \ Software \ ODBC \ ODBCINST INI \ ODBC DRIVERS ', 'the Adaptive Server Anywhere 8.0, RegString! , 'Installed')
Answer2=RegistrySet (' HKEY_LOCAL_MACHINE \ Software \ ODBC \ ODBCINST INI \ the Adaptive Server Anywhere 8.0 ', 'Driver', RegString! , ls_driver)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull