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;

CodePudding user response:

Didn't see you EXCEPTION screenshots, try this:
Db1. Connected:=False;
Db1. Params. Values: [' USERNAME ']=Use_name;
Db1. Params. Values: [' PASSWORD ']=Pas_word;
Db1. LoginPrompt:=False;
Db1. Connected:=True;//not even
=================================
Db1. Close;
Db1. Params. Values: [' USERNAME ']=QuotedStr (Use_name);
Db1. Params. Values: [' PASSWORD ']=QuotedStr (Pas_word);
Db1. LoginPrompt:=False;
Db1. Open;//even

CodePudding user response:

The
refer to the original poster zengwj1537 response:
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;


Warrior, or even not,,

CodePudding user response:

reference 1st floor doloopcn response:
didn't see you EXCEPTION screenshots, try this:
Db1. Connected:=False;
Db1. Params. Values: [' USERNAME ']=Use_name;
Db1. Params. Values: [' PASSWORD ']=Pas_word;
Db1. LoginPrompt:=False;
Db1. Connected:=True;//not even
=================================
Db1. Close;
Db1. Params. Values: [' USERNAME ']=QuotedStr (Use_name);
Db1. Params. Values: [' PASSWORD ']=QuotedStr (Pas_word);
Db1. LoginPrompt:=False;
Db1. Open;//not even


Warrior, or even not,,
What attribute to set up the database controls?

CodePudding user response:

Why use bde, in the latest edition has abandoned xe7 bde, so I suggest that you don't study bde, directly use ADO suite,

CodePudding user response:

I think so. Every client with BDE words written application to configure the BDE to run the program, it is better to directly ADO?nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related