数据库连接

 1 procedure TfmMain.btn3Click(Sender: TObject);
 2 var
 3   Con: TUniConnection;
 4 begin
 5   Con := TUniConnection.Create(nil);
 6   try
 7     try
 8       Con.ProviderName := 'SQL Server';
 9       Con.server := 'T3000';
10       Con.Username := 'sa';
11       Con.Password := '';
12       Con.Database := 'jzxxsjs_test';
13       Con.LoginPrompt := False;
14       Con.Connect;
15       Con.ExecSQL('truncate table XS_RT_DATA', []);
16       with TIniFile.Create(ChangeFileExt(GetModuleName(0), '.ini')) do
17       begin
18         WriteInteger('Config', 'LastID', 0);
19         Free;
20       end;
21       ShowMessage('处理完成');
22       Con.Disconnect;
23     except
24       on E: Exception do
25       begin
26         ShowMessage(E.Message);
27       end;
28     end;
29   finally
30     Con.Free;
31   end;
32 end;
原文地址:https://www.cnblogs.com/zhier/p/5237567.html