Skip to content

Commit 7124cb0

Browse files
Add files via upload
1 parent f71450c commit 7124cb0

6 files changed

+1179
-0
lines changed

ConnectionString.dpr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
program ConnectionString;
2+
3+
uses
4+
Vcl.Forms,
5+
uMain in 'uMain.pas' {Form1};
6+
7+
{$R *.res}
8+
9+
begin
10+
Application.Initialize;
11+
Application.MainFormOnTaskbar := True;
12+
Application.CreateForm(TForm1, Form1);
13+
Application.Run;
14+
end.

ConnectionString.dproj

Lines changed: 973 additions & 0 deletions
Large diffs are not rendered by default.

ConnectionString.dproj.local

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<BorlandProject>
3+
<Transactions>
4+
<Transaction>2024/06/01 14:07:18.314,=C:\Users\tcoat\OneDrive\Documents\Embarcadero\Studio\Projects\Unit1.pas</Transaction>
5+
<Transaction>2024/06/01 14:18:41.233,C:\Work\TC Solutions\repos\delphi-connection\uMain.pas=C:\Users\tcoat\OneDrive\Documents\Embarcadero\Studio\Projects\Unit1.pas</Transaction>
6+
<Transaction>2024/06/01 14:18:41.233,C:\Work\TC Solutions\repos\delphi-connection\uMain.dfm=C:\Users\tcoat\OneDrive\Documents\Embarcadero\Studio\Projects\Unit1.dfm</Transaction>
7+
<Transaction>2024/06/01 17:39:41.874,C:\Work\TC Solutions\repos\delphi-connection\ConnectionString.dproj=C:\Users\tcoat\OneDrive\Documents\Embarcadero\Studio\Projects\Project1.dproj</Transaction>
8+
</Transactions>
9+
</BorlandProject>

ConnectionString.res

110 KB
Binary file not shown.

uMain.dfm

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
object Form1: TForm1
2+
Left = 0
3+
Top = 0
4+
BorderStyle = bsDialog
5+
Caption = 'Check Database Connection'
6+
ClientHeight = 473
7+
ClientWidth = 541
8+
Color = clBtnFace
9+
Font.Charset = DEFAULT_CHARSET
10+
Font.Color = clWindowText
11+
Font.Height = -12
12+
Font.Name = 'Segoe UI'
13+
Font.Style = []
14+
Position = poMainFormCenter
15+
OnCreate = FormCreate
16+
TextHeight = 15
17+
object Label1: TLabel
18+
Left = 8
19+
Top = 221
20+
Width = 100
21+
Height = 15
22+
Caption = 'Messages / Errors:'
23+
Font.Charset = DEFAULT_CHARSET
24+
Font.Color = clWindowText
25+
Font.Height = -12
26+
Font.Name = 'Segoe UI'
27+
Font.Style = [fsBold]
28+
ParentFont = False
29+
end
30+
object Label2: TLabel
31+
Left = 8
32+
Top = 421
33+
Width = 519
34+
Height = 45
35+
Caption =
36+
'Note: Even when "Allow password saving" is checked, the password' +
37+
' is not contained in the connection string after creating a con' +
38+
'nection string. You will have to manually add this if you want t' +
39+
'o "Test Connection"'
40+
Font.Charset = DEFAULT_CHARSET
41+
Font.Color = clWindowText
42+
Font.Height = -12
43+
Font.Name = 'Segoe UI'
44+
Font.Style = [fsBold]
45+
ParentFont = False
46+
WordWrap = True
47+
end
48+
object Memo1: TMemo
49+
Left = 8
50+
Top = 48
51+
Width = 521
52+
Height = 161
53+
Lines.Strings = (
54+
'Memo1')
55+
TabOrder = 0
56+
end
57+
object Button1: TButton
58+
Left = 8
59+
Top = 8
60+
Width = 169
61+
Height = 25
62+
Caption = 'Build Connection String'
63+
TabOrder = 1
64+
OnClick = Button1Click
65+
end
66+
object Button2: TButton
67+
Left = 183
68+
Top = 8
69+
Width = 169
70+
Height = 25
71+
Caption = 'Test Connection'
72+
TabOrder = 2
73+
OnClick = Button2Click
74+
end
75+
object Button3: TButton
76+
Left = 358
77+
Top = 8
78+
Width = 169
79+
Height = 25
80+
Caption = 'Copy Connection String'
81+
TabOrder = 3
82+
OnClick = Button3Click
83+
end
84+
object Memo2: TMemo
85+
Left = 8
86+
Top = 242
87+
Width = 521
88+
Height = 161
89+
Lines.Strings = (
90+
'Memo1')
91+
TabOrder = 4
92+
WordWrap = False
93+
end
94+
object ADOConnection1: TADOConnection
95+
Left = 360
96+
Top = 96
97+
end
98+
end

uMain.pas

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
unit uMain;
2+
3+
interface
4+
5+
uses
6+
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
7+
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Data.DB, Data.Win.ADODB;
8+
9+
type
10+
TForm1 = class(TForm)
11+
ADOConnection1: TADOConnection;
12+
Memo1: TMemo;
13+
Button1: TButton;
14+
Button2: TButton;
15+
Button3: TButton;
16+
Memo2: TMemo;
17+
Label1: TLabel;
18+
Label2: TLabel;
19+
procedure Button1Click(Sender: TObject);
20+
procedure Button2Click(Sender: TObject);
21+
procedure Button3Click(Sender: TObject);
22+
procedure FormCreate(Sender: TObject);
23+
private
24+
{ Private declarations }
25+
procedure LogMessage(const AMessage: string);
26+
public
27+
{ Public declarations }
28+
end;
29+
30+
var
31+
Form1: TForm1;
32+
33+
implementation
34+
35+
{$R *.dfm}
36+
37+
procedure TForm1.Button1Click(Sender: TObject);
38+
begin
39+
Memo1.Lines.Text := PromptDataSource(self.Handle, '');
40+
end;
41+
42+
procedure TForm1.Button2Click(Sender: TObject);
43+
begin
44+
if Memo1.Lines.Text = '' then
45+
begin
46+
ShowMessage('No connection string entered');
47+
Exit;
48+
end;
49+
50+
try
51+
ADOConnection1.LoginPrompt := False;
52+
ADOConnection1.ConnectionString := Memo1.Lines.Text;
53+
LogMessage('Connection to database...');
54+
ADOConnection1.Connected := True;
55+
LogMessage('Opened connection to database');
56+
ADOConnection1.Connected := False;
57+
LogMessage('Closed connection to database');
58+
except
59+
on e: Exception do
60+
begin
61+
LogMessage('Exception opening database ' + e.Message);
62+
if ADOConnection1.Connected then
63+
ADOConnection1.Connected := False;
64+
end;
65+
end;
66+
end;
67+
68+
procedure TForm1.Button3Click(Sender: TObject);
69+
begin
70+
Memo1.CopyToClipboard;
71+
end;
72+
73+
procedure TForm1.FormCreate(Sender: TObject);
74+
begin
75+
Memo1.Clear;
76+
Memo2.Clear;
77+
end;
78+
79+
procedure TForm1.LogMessage(const AMessage: string);
80+
begin
81+
Memo2.Lines.Add(DateTimeToStr(Now) + ' - ' + AMessage);
82+
end;
83+
84+
end.
85+

0 commit comments

Comments
 (0)