Home > Back-end > Code is used to implement the BDE automatically create the alias
Code is used to implement the BDE automatically create the alias
Time:09-26
Masters: I want to realize the function: according to my custom AliasName ServerName, DataBaseName, UserName, PassWord, and create an alias in BDE automatic system, and then my alias in Delphi query database
The code is as follows:
procedure TForm1. Btn1Click (Sender: TObject); Var BDE_Alias Ser_name, dat_name Use_name, Pas_word: string; DataParams: TStringList;//the string list The begin Ser_name:=edt1. Text;//the server name Dat_name:=edt2. Text;//database name path Use_name:=edt3. Text;//database user login name Pas_word:=edt4. Text;//database user password BDE_Alias:=edt5. Text;//Aliasname
DataParams:=TStringList. Create; Try DataParams. The Clear; DataParams. Add (' SERVER NAME='+ ser_name);//the server name or IP DataParams. The Add (+ dat_name DATABASENAME=); DataParams. Add (' USER NAME='+ Use_name); DataParams. Add (' PASSWORD='+ Pas_word); If the session. IsAlias (bde_alias) then The begin The session. ModifyAlias (bde_alias dataparams); End The else The begin Session. AddAlias (bde_alias, MSSQL, dataparams); end; The Session. SaveConfigFile; Never dull. DataParams. Free; The exit; end; DataParams. Free; Db1. Connected:=False; Db1. Params. Values: [' USERNAME ']=Use_name; Db1. Params. Values: [' PASSWORD ']=Pas_word; Db1. LoginPrompt:=False; Db1. Connected:=True;//not even
Qry1. DatabaseName:=db1. DatabaseName; Qry1. Close; Qry1. SQL. The Clear; Qry1. SQL. The Add (' select * from books'); Qry1. Open; Qry1. Active:=True; end;
Connect the code above is not BDE, db1. The connect:=true error, mean even,, ask everybody to give directions the younger brother, how to use the code to implement this function;