-
Notifications
You must be signed in to change notification settings - Fork 2
/
ODBCLOGN.FRM
485 lines (436 loc) · 13.4 KB
/
ODBCLOGN.FRM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
VERSION 5.00
Begin VB.Form frmODBCLogon
BorderStyle = 3 'Fixed Dialog
Caption = "ODBC Logon"
ClientHeight = 3180
ClientLeft = 450
ClientTop = 1455
ClientWidth = 4470
ControlBox = 0 'False
BeginProperty Font
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
HelpContextID = 2016138
Icon = "ODBCLOGN.frx":0000
KeyPreview = -1 'True
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3180
ScaleWidth = 4470
ShowInTaskbar = 0 'False
Begin VB.CommandButton cmdRegister
Caption = "&Register"
Height = 450
Left = 120
MaskColor = &H00000000&
TabIndex = 15
Top = 2655
Width = 1440
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "Cancel"
Height = 450
Left = 3075
MaskColor = &H00000000&
TabIndex = 13
Top = 2655
Width = 1260
End
Begin VB.CommandButton cmdOK
Caption = "&OK"
Default = -1 'True
Height = 450
Left = 1740
MaskColor = &H00000000&
TabIndex = 12
Top = 2655
Width = 1260
End
Begin VB.Frame fraConnection
Caption = "Connection Values"
Height = 2415
Left = 120
TabIndex = 14
Top = 120
Width = 4230
Begin VB.TextBox txtUID
Height = 300
Left = 1125
TabIndex = 3
Top = 600
Width = 3015
End
Begin VB.TextBox txtPWD
Height = 300
IMEMode = 3 'DISABLE
Left = 1125
PasswordChar = "*"
TabIndex = 5
Top = 930
Width = 3015
End
Begin VB.TextBox txtDatabase
Height = 300
Left = 1125
TabIndex = 7
Top = 1260
Width = 3015
End
Begin VB.ComboBox cboDSNList
Height = 315
ItemData = "ODBCLOGN.frx":000C
Left = 1125
List = "ODBCLOGN.frx":000E
Sorted = -1 'True
TabIndex = 1
Text = "
Top = 240
Width = 3000
End
Begin VB.TextBox txtServer
Enabled = 0 'False
Height = 330
Left = 1125
TabIndex = 11
Top = 1935
Width = 3015
End
Begin VB.ComboBox cboDrivers
Enabled = 0 'False
Height = 315
ItemData = "ODBCLOGN.frx":0010
Left = 1125
List = "ODBCLOGN.frx":0012
Sorted = -1 'True
Style = 2 'Dropdown List
TabIndex = 9
Top = 1590
Width = 3015
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "&DSN:"
Height = 195
Index = 0
Left = 135
TabIndex = 0
Top = 285
Width = 360
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "&UID:"
Height = 195
Index = 1
Left = 135
TabIndex = 2
Top = 630
Width = 330
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "&Password:"
Height = 195
Index = 2
Left = 135
TabIndex = 4
Top = 975
Width = 750
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "Data&base:"
Height = 195
Index = 3
Left = 135
TabIndex = 6
Top = 1320
Width = 750
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "Dri&ver:"
Enabled = 0 'False
Height = 195
Index = 4
Left = 135
TabIndex = 8
Top = 1665
Width = 495
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "&Server:"
Enabled = 0 'False
Height = 195
Index = 5
Left = 135
TabIndex = 10
Top = 2010
Width = 540
End
End
End
Attribute VB_Name = "frmODBCLogon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'>>>>>>>>>>>>>>>>>>>>>>>>
Const FORMCAPTION = "ODBC Logon"
Const BUTTON1 = "&OK"
Const BUTTON2 = "&Cancel"
Const BUTTON3 = "&Register"
Const FRAME1 = "Connect Values:"
Const Label1 = "&DSN:"
Const Label2 = "&UID:"
Const LABEL3 = "&Password:"
Const LABEL4 = "Data&base:"
Const LABEL5 = "Dri&ver:"
Const LABEL6 = "&Server:"
Const MSG1 = "Enter ODBC Connection Parameters"
Const MSG2 = "Opening ODBC Database"
Const MSG3 = "Enter Driver Name:"
Const MSG4 = "Driver Name"
Const MSG5 = "This Datasource has not been Registered, this will now be attempted for you!"
Const MSG7 = "Invalid Parameter(s), Please try again!"
Const MSG8 = "Query Timeout Could not be set, default will be used!"
Const MSG9 = "Datasource Registration Succeeded, proceed with Open."
Const MSG10 = "Please enter a DSN!"
Const MSG11 = "Please select a Driver!"
Const MSG12 = "You must Close First!"
'>>>>>>>>>>>>>>>>>>>>>>>>
Dim mbBeenLoaded As Integer
Public DBOpened As Boolean
Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv&, ByVal fDirection%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDescription$, ByVal cbDescriptionMax%, pcbDescription%) As Integer
Private Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&)
Const SQL_SUCCESS As Long = 0
Const SQL_FETCH_NEXT As Long = 1
Private Sub cboDSNList_Change()
If Len(cboDSNList.Text) = 0 Or cboDSNList.Text = "(None)" Then
txtServer.Enabled = True
cboDrivers.Enabled = True
lblLabels(4).Enabled = True
lblLabels(5).Enabled = True
Else
txtServer.Enabled = False
cboDrivers.Enabled = False
lblLabels(4).Enabled = False
lblLabels(5).Enabled = False
End If
End Sub
Private Sub cmdCancel_Click()
gbDBOpenFlag = False
gsDBName = vbNullString
DBOpened = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
On Error GoTo cmdOK_ClickErr
Dim sConnect As String
Dim dbTemp As Database
MsgBar MSG2, True
If frmMDI.mnuPOpenOnStartup.Checked Then
Me.Refresh
End If
Screen.MousePointer = vbHourglass
If Len(cboDSNList.Text) > 0 Then
sConnect = "ODBC;DSN=" & cboDSNList.Text & ";"
Else
sConnect = "ODBC;Driver={" & cboDrivers.Text & "};"
sConnect = sConnect & "Server=" & txtServer.Text & ";"
End If
sConnect = sConnect & "UID=" & txtUID.Text & ";"
sConnect = sConnect & "PWD=" & txtPWD.Text & ";"
If Len(txtDatabase.Text) > 0 Then
sConnect = sConnect & "Database=" & txtDatabase.Text & ";"
End If
Set dbTemp = gwsMainWS.OpenDatabase("", 0, 0, sConnect)
If gbDBOpenFlag Then
CloseCurrentDB
If gbDBOpenFlag Then
Beep
MsgBox MSG12, 48
Me.Hide
Exit Sub
End If
End If
'success
DBOpened = True
'save the values
gsODBCDatasource = cboDSNList.Text
gsDBName = gsODBCDatasource
gsODBCDatabase = txtDatabase.Text
gsODBCUserName = txtUID.Text
gsODBCPassword = txtPWD.Text
gsODBCDriver = cboDrivers.Text
gsODBCServer = txtServer.Text
gsDataType = gsSQLDB
Set gdbCurrentDB = dbTemp
GetODBCConnectParts gdbCurrentDB.Connect
cboDSNList.Text = gsODBCDatasource
txtDatabase.Text = gsODBCDatabase
txtUID.Text = gsODBCUserName
txtPWD.Text = gsODBCPassword
frmMDI.Caption = "VisData:" & gsDBName & "." & gsODBCDatabase
gdbCurrentDB.QueryTimeout = glQueryTimeout
gbDBOpenFlag = True
AddMRU
Screen.MousePointer = vbDefault
Me.Hide
Exit Sub
cmdOK_ClickErr:
Screen.MousePointer = vbDefault
gbDBOpenFlag = False
If Len(cboDSNList.Text) > 0 Then
If InStr(1, Error, "ODBC--connection to '" & cboDSNList.Text & "' failed") > 0 Then
Beep
MsgBox MSG5, 48
txtDatabase.Text = vbNullString
txtUID.Text = vbNullString
txtPWD.Text = vbNullString
If RegisterDB((cboDSNList.Text)) Then
MsgBox MSG9, 48
End If
ElseIf InStr(1, Error, "Login failed") > 0 Then
Beep
MsgBox MSG7, 48
ElseIf InStr(1, Error, "QueryTimeout property") > 0 Then
If glQueryTimeout <> 5 Then
Beep
MsgBox MSG8, 48
End If
Resume Next
Else
ShowError
End If
End If
MsgBar MSG1, False
If Err = 3059 Then
Unload Me
End If
End Sub
Private Sub cmdRegister_Click()
On Error GoTo cmdRegister_ClickErr
If Len(cboDSNList.Text) = 0 Then
MsgBox MSG10, vbInformation, Me.Caption
Exit Sub
End If
If Len(cboDrivers.Text) = 0 Then
MsgBox MSG11, vbInformation, Me.Caption
Exit Sub
End If
'try to register it
DBEngine.RegisterDatabase cboDSNList.Text, cboDrivers.Text, False, vbNullString
MsgBox MSG9, vbInformation
Exit Sub
cmdRegister_ClickErr:
ShowError
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF1 And Shift = 0 Then
DisplayTopic 2016138
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Me.Caption = FORMCAPTION
cmdOK.Caption = BUTTON1
cmdCancel.Caption = BUTTON2
cmdRegister.Caption = BUTTON3
fraConnection.Caption = FRAME1
lblLabels(0).Caption = Label1
lblLabels(1).Caption = Label2
lblLabels(2).Caption = LABEL3
lblLabels(3).Caption = LABEL4
lblLabels(4).Caption = LABEL5
lblLabels(5).Caption = LABEL6
GetDSNsAndDrivers
MsgBar MSG1, False
cboDSNList.Text = gsODBCDatasource
txtDatabase.Text = gsODBCDatabase
txtUID.Text = gsODBCUserName
txtPWD.Text = gsODBCPassword
If Len(gsODBCDriver) > 0 Then
For i = 0 To cboDrivers.ListCount - 1
If cboDrivers.List(i) = gsODBCDriver Then
cboDrivers.ListIndex = i
Exit For
End If
Next
End If
txtServer.Text = gsODBCServer
mbBeenLoaded = True
End Sub
Private Sub cboDSNList_Click()
cboDSNList_Change
End Sub
Sub GetDSNsAndDrivers()
On Error Resume Next
Dim i As Integer
Dim sDSNItem As String * 1024
Dim sDRVItem As String * 1024
Dim sDSN As String
Dim sDRV As String
Dim iDSNLen As Integer
Dim iDRVLen As Integer
Dim lHenv As Long 'handle to the environment
cboDSNList.AddItem "(None)"
'get the DSNs
If SQLAllocEnv(lHenv) <> -1 Then
Do Until i <> SQL_SUCCESS
sDSNItem = Space(1024)
sDRVItem = Space(1024)
i = SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen)
sDSN = VBA.Left(sDSNItem, iDSNLen)
sDRV = VBA.Left(sDRVItem, iDRVLen)
If sDSN <> Space(iDSNLen) Then
cboDSNList.AddItem sDSN
cboDrivers.AddItem sDRV
End If
Loop
End If
'remove the dupes
If cboDSNList.ListCount > 0 Then
With cboDrivers
If .ListCount > 1 Then
i = 0
While i < .ListCount
If .List(i) = .List(i + 1) Then
.RemoveItem (i)
Else
i = i + 1
End If
Wend
End If
End With
End If
cboDSNList.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBar vbNullString, False
End Sub
Private Function RegisterDB(rsDatasource As String) As Integer
On Error GoTo RDBErr
Dim sDriver As String
sDriver = InputBox(MSG3, MSG4, gsDEFAULT_DRIVER)
If sDriver <> gsDEFAULT_DRIVER Then
DBEngine.RegisterDatabase rsDatasource, sDriver, False, vbNullString
Else
DBEngine.RegisterDatabase rsDatasource, sDriver, True, vbNullString
End If
RegisterDB = True
Exit Function
RDBErr:
RegisterDB = False
End Function