我一般是把数据库连接参数保存到INI文件中,然后再组合成为TADOConnection.ConnetionString.例程如下:
function GetConnectionString: string;
var
SYSINI: TINIFile;
ServerName, UserName, Password, InitDB: string;
tmpstr: string;
begin
SYSINI := TIniFile.Create('DB.INI');
try
ServerName := SYSINI.ReadString('Database', 'ServerName', '');
UserName := SYSINI.ReadString('Database', 'UserName', '');
InitDB := SYSINI.ReadString('Database', 'InitDB', '');
tmpstr := SYSINI.ReadString('Database', 'Password', '');
Password := Decrypt(tmpstr, Key);
Result := '';
Result := 'Provider=SQLOLEDB.1;Password=' + Password + ';Persist Security Info=True;User ID=' + UserName + ';Initial Catalog=' + InitDB + ';Data Source=' + ServerName;
finally
SYSINI.Free;
end;
end;procedure SetConnectionString(ServerName, UserName, Password, InitDB: string);
var
SYSINI: TINIFile;
tmpstr: string;
begin
SYSINI := TIniFile.Create('DB.INI');
try
with SYSINI do
begin
WriteString('Database', 'ServerName', ServerName);
WriteString('Database', 'UserName', UserName);
WriteString('Database', 'InitDB', InitDB);
tmpstr := Encrypt(Password, Key);
WriteString('Database', 'Password', tmpstr);
end;
finally
SYSINI.Free;
end;
end;
function GetConnectionString: string;
var
SYSINI: TINIFile;
ServerName, UserName, Password, InitDB: string;
tmpstr: string;
begin
SYSINI := TIniFile.Create('DB.INI');
try
ServerName := SYSINI.ReadString('Database', 'ServerName', '');
UserName := SYSINI.ReadString('Database', 'UserName', '');
InitDB := SYSINI.ReadString('Database', 'InitDB', '');
tmpstr := SYSINI.ReadString('Database', 'Password', '');
Password := Decrypt(tmpstr, Key);
Result := '';
Result := 'Provider=SQLOLEDB.1;Password=' + Password + ';Persist Security Info=True;User ID=' + UserName + ';Initial Catalog=' + InitDB + ';Data Source=' + ServerName;
finally
SYSINI.Free;
end;
end;procedure SetConnectionString(ServerName, UserName, Password, InitDB: string);
var
SYSINI: TINIFile;
tmpstr: string;
begin
SYSINI := TIniFile.Create('DB.INI');
try
with SYSINI do
begin
WriteString('Database', 'ServerName', ServerName);
WriteString('Database', 'UserName', UserName);
WriteString('Database', 'InitDB', InitDB);
tmpstr := Encrypt(Password, Key);
WriteString('Database', 'Password', tmpstr);
end;
finally
SYSINI.Free;
end;
end;
写上 ADO的ConnectionString 去.BDE + paradox 绝对比 ADO + paradox 要快和稳定,如果你是
单机环境下, 我想用BDE较好.