我一般是把数据库连接参数保存到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;

解决方案 »

  1.   

    先建一扩展名为".udl"的文本文件(假设为"test.udl"),双击之,进行相应的设置,指定ConnectionString:='FILE NAME='+ExtractFilePath(Application.ExeName)+'test.udl';
      

  2.   

    先建一扩展名为".udl"的文本文件(假设为"test.udl"),双击之,进行相应的设置,指定ConnectionString:='FILE NAME='+ExtractFilePath(Application.ExeName)+'test.udl';
      

  3.   

    那你为何不用BDE,DElphi自己的用着多方便。
      

  4.   

    那你为何不用BDE,DElphi自己的用着多方便。
      

  5.   

    那你为何不用BDE,DElphi自己的用着多方便。
      

  6.   

    目前我使用BDE,但分发程序时需打包BDE,所发想转用ADO,由于系统即使用了SQLserver也使用了pardox,sqlserver连接已解决,但如何连接到一个本地aprdox表上却很头痛,大家出出点子,分不够还可再加!
      

  7.   

    我能不能问问为什么要建立ini文件或udl文件呀!?
      

  8.   

    所生成的 udl 也是用本文格式存, 可以直接把udl的内容
    写上 ADO的ConnectionString 去.BDE + paradox 绝对比 ADO + paradox 要快和稳定,如果你是
    单机环境下, 我想用BDE较好.
      

  9.   

    你使用paradox还不是在打包时,使用bde,建议你吧数据库统一起来,另外使用paradox最好用delphi 的控件