码迷,mamicode.com
首页 > 其他好文 > 详细

TUniConnection连接

时间:2016-02-21 06:33:28      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:

ChangeFileExt

RealTime_Server.ini

[Config]
FromConStr=DBTYPE=0|SERVER=127.0.0.1|PORT=7788|DBNAME=jzxtld|USERNAME=sa|PASSWORD=admin
ToConStr=DBTYPE=0|SERVER=127.0.0.1|PORT=7788|DBNAME=jzxxsjs|USERNAME=sa|PASSWORD=admin

 
 1 procedure StrToUniCon(AStr: string; UniCon: TUniConnection);
 2   function GetDBType(i: Integer): string;
 3   begin
 4     case i of
 5       0:
 6         begin
 7           Result := SQL Server;
 8         end;
 9       1:
10         begin
11           Result := Oracle;
12         end else
13       begin
14         Result := ‘‘;
15       end;
16     end;
17   end;
18 var
19   L: TStrings;
20 begin
21   if Trim(AStr) = ‘‘ then Exit;
22   if (AStr <> ‘‘) and (AStr[Length(AStr)] = |) then system.Delete(AStr, Length(AStr), 1);
23   L := TStringList.Create;
24   try
25     L.Delimiter := |;
26     L.DelimitedText := AStr;
27     if L.Count = 6 then
28     begin
29       UniCon.LoginPrompt := False;
30       UniCon.ProviderName := GetDBType(StrToInt(L.Values[DBTYPE]));
31       if SameText(UniCon.ProviderName, Oracle) then
32       begin
33         UniCon.SpecificOptions.Clear;
34         UniCon.SpecificOptions.Add(Oracle.Direct=True);
35         UniCon.SpecificOptions.Add(Oracle.PrecisionInteger=11);
36         UniCon.server := L.Values[SERVER] + : + L.Values[PORT] + : + L.Values[DBNAME];
37       end else
38       begin
39         UniCon.server := L.Values[SERVER] + , + L.Values[PORT];
40         UniCon.Database := L.Values[DBNAME];
41       end;
42       UniCon.Username := L.Values[USERNAME];
43       UniCon.Password := L.Values[PASSWORD];
44     end;
45   finally
46     L.Free;
47   end;
48 end;
 
1
procedure TfmDBConectString.bt_testconnClick(Sender: TObject); 2 var 3 Con: TUniConnection; 4 begin 5 if rgDbType.ItemIndex = -1 then 6 begin 7 Application.MessageBox(请选择数据库类型!, 警告, MB_ICONWARNING or MB_APPLMODAL); 8 Exit; 9 end; 10 Con := TUniConnection.Create(nil); 11 try 12 try 13 StrToUniCon(Self.GetConnectXML, Con); 14 Con.Connect; 15 ShowMessage(连接成功!); 16 Con.Disconnect; 17 except 18 on E: Exception do 19 begin 20 ShowMessage(E.Message); 21 end; 22 end; 23 finally 24 Con.Free; 25 end; 26 end;

 

 1 procedure TSyncThread.LoadFromCon(Uni: TUniConnection);
 2 var
 3   S:String;
 4 begin
 5   with TIniFile.Create(ChangeFileExt(GetModuleName(0),.ini)) do
 6   begin
 7     S:=ReadString(Config,FromConStr,‘‘);
 8     if S<>‘‘ then
 9     begin
10       StrToUniCon(S,Uni);
11     end;
12     Free;
13   end;
14 end;

 

 1  1 function TfmMain.GetToConStr: string;
 2  2 begin
 3  3   with TIniFile.Create(ChangeFileExt(GetModuleName(0), .ini)) do
 4  4   begin
 5  5     Result := ReadString(Config, ToConStr, ‘‘);
 6  6     Free;
 7  7   end;
 8  8 end;
 9  9 
10 10 procedure TfmMain.SetToConStr(const Value: string);
11 11 begin
12 12   with TIniFile.Create(ChangeFileExt(GetModuleName(0), .ini)) do
13 13   begin
14 14     WriteString(Config, ToConStr, Value);
15 15     Free;
16 16   end;
17 17 end;

 



TUniConnection连接

标签:

原文地址:http://www.cnblogs.com/zhier/p/5204338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!