可以统一的,给你一段我的程序: TSystemFixParam=record SQLServerDefaultPort:int; //SQL Server服务端使用的通信端口,默认是1433。 DBMachineOrIPAddr:string; //SQL服务器的名称或者IP地址,如果为空表示本机。 SQLServerDataBaseName:string; //数据库名称,不能为空。 SQLServerInstanceName:string; //SQL服务器的实例名称,如果为空,表示默认实例。 SQLServerLoginAccount:string; //SQL Server登录帐户名称,为空表示Windows登录。 SQLServerLoginPassWord:string; //帐户与密码,仅在使用混合认证时使用。可以使用 end;procedure TDM.ConnectToMSSQLServer;begin Connection.Close; with FSystemFixParam,Connection do begin //1、本地Windows认证方式: Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WirelessMeterDB;Data Source=(local)/SQLServer2K //2、其它机器的Windows认证方式:Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WirelessMeterDB;Data Source=MachineName/InstanceName //3、本地SQL方式: Provider=SQLOLEDB.1;Password=MyPassWord;Persist Security Info=True;User ID=MyAccount;Initial Catalog=WirelessMeterDB;Data Source=(local)/SQLSERVER2K //4、其它机器的SQL登录方式:Provider=SQLOLEDB.1;Password=MyPassWord;Persist Security Info=True;User ID=MyAccount;Initial Catalog=WirelessMeterDB;Data Source=(MachineName)/InstanceName //ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WirelessMeterDB;Data Source=LGB/FIRSTSQLSERVER2K;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=LGB;'+ //'Use Encryption for Data=False;Tag with column collation when possible=False'; //Exit; if DBMachineOrIPAddr='' then//本地 begin if SQLServerLoginAccount='' then//没有帐户名称,表示以Windowds认证方式登录 begin ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;'+ 'Initial Catalog='+SQLServerDataBaseName+';Data Source=(local)'; if SQLServerInstanceName<>'' then ConnectionString:=ConnectionString+'/'+SQLServerInstanceName; end else//否则是本地混合认证登录 begin ConnectionString:='Provider=SQLOLEDB.1;Password="'+SQLServerLoginPassWord+ '";Persist Security Info=True;User ID='+SQLServerLoginAccount+';Initial Catalog='+SQLServerDataBaseName+';Data Source=(local)';// if SQLServerInstanceName<>'' then ConnectionString:=ConnectionString+'/'+SQLServerInstanceName; end; end else begin//否则SQL Server不在本机。包括局域网络和广域网络。 if SQLServerLoginAccount='' then//没有帐户名称,表示以Windowds认证方式登录 begin //WirelessMeterDB ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog='+SQLServerDataBaseName+';Data Source='+DBMachineOrIPAddr; if SQLServerInstanceName<>'' then ConnectionString:=ConnectionString+'/'+SQLServerInstanceName; end else begin//否则是混合认证登录 ConnectionString:='Provider=SQLOLEDB.1;Data Source='+DBMachineOrIPAddr; if SQLServerInstanceName<>'' then ConnectionString:=ConnectionString+'/'+SQLServerInstanceName; ConnectionString:=ConnectionString+','+IntToStr(SQLServerDefaultPort)+ ';Network Library=DBMSSOCN;Initial Catalog='+SQLServerDataBaseName+ ';User ID='+SQLServerLoginAccount+';Password="'+SQLServerLoginPassWord+'"'; end; end; end;end;