其实是不用的,因为ADO是一次连接,到处运行的,你只要在编程的时候在你的客户端程序设好你的服务器端,这样你的客户端每次登录的时候就会找到你的服务器的。

解决方案 »

  1.   

    如果你的服务器会变,可能你得动态生成TADOConnection.ConnectionString了.我的做法一般是把配置信息,例如服务器名、用户名、口令(加密)和初始数据库都放在INI文件里,然后要用的时候再从里面读取来生成Connectionstring。
    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; 
      

  2.   

    如果你的服务器会变,可能你得动态生成TADOConnection.ConnectionString了.我的做法一般是把配置信息,例如服务器名、用户名、口令(加密)和初始数据库都放在INI文件里,然后要用的时候再从里面读取来生成Connectionstring。
    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; 
      

  3.   

    你只要知道你的 服务器的ip即可,
    这样client 连接到sql server 即可。
    发送数据有很多办法,
    savetofile
    bcp批量复制!