Windows Form File /FormConnection.vb (VB.NET)
1: Option Strict Off
2: Option Explicit On
3: Friend Class FormConnection
4:     Inherits System.Windows.Forms.Form
5: #Region "Windows Form Designer generated code "
6:     Public Sub New()
7:         MyBase.New()
8:         If m_vb6FormDefInstance Is Nothing Then
9:             If m_InitializingDefInstance Then
10:                 m_vb6FormDefInstance = Me
11:             Else
12:                 Try  
13:                     'For the start-up form, the first instance created is the default instance.  
14:                     If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
15:                         m_vb6FormDefInstance = Me
16:                     End If
17:                 Catch
18:                 End Try
19:             End If
20:         End If
21:         'This call is required by the Windows Form Designer.  
22:         InitializeComponent()
23:     End Sub
24:     'Form overrides dispose to clean up the component list.  
25:     Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
26:         If Disposing Then
27:             If Not components Is Nothing Then
28:                 components.Dispose()
29:             End If
30:         End If
31:         MyBase.Dispose(Disposing)
32:     End Sub
33:     'Required by the Windows Form Designer  
34:     Private components As System.ComponentModel.IContainer
35:     Public ToolTip1 As System.Windows.Forms.ToolTip
36:     Public WithEvents CheckTrustedConnection As System.Windows.Forms.CheckBox
37:     Public WithEvents CommandTestConnection As System.Windows.Forms.Button
38:     Public WithEvents TextDatabasePassword As System.Windows.Forms.TextBox
39:     Public WithEvents TextDatabaseUserName As System.Windows.Forms.TextBox
40:     Public WithEvents TextDatabaseServer As System.Windows.Forms.TextBox
41:     Public WithEvents LabelPassword As System.Windows.Forms.Label
42:     Public WithEvents LabelUserName As System.Windows.Forms.Label
43:     Public WithEvents LabelDatabaseServer As System.Windows.Forms.Label
44:     Public WithEvents FrameEditDatabase As System.Windows.Forms.GroupBox
45:     Public WithEvents CommandCancel As System.Windows.Forms.Button
46:     Public WithEvents CommandOK As System.Windows.Forms.Button
47:     'NOTE: The following procedure is required by the Windows Form Designer  
48:     'It can be modified using the Windows Form Designer.  
49:     'Do not modify it using the code editor.  
50:     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
51:         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FormConnection))
52:         Me.components = New System.ComponentModel.Container()
53:         Me.ToolTip1 = New System.Windows.Forms.ToolTip(components)
54:         Me.ToolTip1.Active = True
55:         Me.CheckTrustedConnection = New System.Windows.Forms.CheckBox
56:         Me.FrameEditDatabase = New System.Windows.Forms.GroupBox
57:         Me.CommandTestConnection = New System.Windows.Forms.Button
58:         Me.TextDatabasePassword = New System.Windows.Forms.TextBox
59:         Me.TextDatabaseUserName = New System.Windows.Forms.TextBox
60:         Me.TextDatabaseServer = New System.Windows.Forms.TextBox
61:         Me.LabelPassword = New System.Windows.Forms.Label
62:         Me.LabelUserName = New System.Windows.Forms.Label
63:         Me.LabelDatabaseServer = New System.Windows.Forms.Label
64:         Me.CommandCancel = New System.Windows.Forms.Button
65:         Me.CommandOK = New System.Windows.Forms.Button
66:         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
67:         Me.Text = "Edit Database Connection"
68:         Me.ClientSize = New System.Drawing.Size(359, 200)
69:         Me.Location = New System.Drawing.Point(3, 22)
70:         Me.Icon = CType(resources.GetObject("FormConnection.Icon"), System.Drawing.Icon)
71:         Me.MaximizeBox = False
72:         Me.MinimizeBox = False
73:         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
74:         Me.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
75:         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
76:         Me.BackColor = System.Drawing.SystemColors.Control
77:         Me.ControlBox = True
78:         Me.Enabled = True
79:         Me.KeyPreview = False
80:         Me.Cursor = System.Windows.Forms.Cursors.Default
81:         Me.RightToLeft = System.Windows.Forms.RightToLeft.No
82:         Me.ShowInTaskbar = True
83:         Me.HelpButton = False
84:         Me.WindowState = System.Windows.Forms.FormWindowState.Normal
85:         Me.Name = "FormConnection"
86:         Me.CheckTrustedConnection.Text = "Use Trusted Connection?"
87:         Me.CheckTrustedConnection.Size = New System.Drawing.Size(161, 13)
88:         Me.CheckTrustedConnection.Location = New System.Drawing.Point(104, 112)
89:         Me.CheckTrustedConnection.TabIndex = 10
90:         Me.CheckTrustedConnection.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
91:         Me.CheckTrustedConnection.CheckAlign = System.Drawing.ContentAlignment.MiddleLeft
92:         Me.CheckTrustedConnection.BackColor = System.Drawing.SystemColors.Control
93:         Me.CheckTrustedConnection.CausesValidation = True
94:         Me.CheckTrustedConnection.Enabled = True
95:         Me.CheckTrustedConnection.ForeColor = System.Drawing.SystemColors.ControlText
96:         Me.CheckTrustedConnection.Cursor = System.Windows.Forms.Cursors.Default
97:         Me.CheckTrustedConnection.RightToLeft = System.Windows.Forms.RightToLeft.No
98:         Me.CheckTrustedConnection.Appearance = System.Windows.Forms.Appearance.Normal
99:         Me.CheckTrustedConnection.TabStop = True
100:         Me.CheckTrustedConnection.CheckState = System.Windows.Forms.CheckState.Unchecked
101:         Me.CheckTrustedConnection.Visible = True
102:         Me.CheckTrustedConnection.Name = "CheckTrustedConnection"
103:         Me.FrameEditDatabase.Text = "Database Details"
104:         Me.FrameEditDatabase.Size = New System.Drawing.Size(353, 161)
105:         Me.FrameEditDatabase.Location = New System.Drawing.Point(0, 0)
106:         Me.FrameEditDatabase.TabIndex = 2
107:         Me.FrameEditDatabase.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
108:         Me.FrameEditDatabase.BackColor = System.Drawing.SystemColors.Control
109:         Me.FrameEditDatabase.Enabled = True
110:         Me.FrameEditDatabase.ForeColor = System.Drawing.SystemColors.ControlText
111:         Me.FrameEditDatabase.RightToLeft = System.Windows.Forms.RightToLeft.No
112:         Me.FrameEditDatabase.Visible = True
113:         Me.FrameEditDatabase.Name = "FrameEditDatabase"
114:         Me.CommandTestConnection.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
115:         Me.CommandTestConnection.Text = "Test Connection"
116:         Me.CommandTestConnection.Size = New System.Drawing.Size(105, 25)
117:         Me.CommandTestConnection.Location = New System.Drawing.Point(240, 128)
118:         Me.CommandTestConnection.TabIndex = 9
119:         Me.ToolTip1.SetToolTip(Me.CommandTestConnection, "Test this Database Connection")
120:         Me.CommandTestConnection.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
121:         Me.CommandTestConnection.BackColor = System.Drawing.SystemColors.Control
122:         Me.CommandTestConnection.CausesValidation = True
123:         Me.CommandTestConnection.Enabled = True
124:         Me.CommandTestConnection.ForeColor = System.Drawing.SystemColors.ControlText
125:         Me.CommandTestConnection.Cursor = System.Windows.Forms.Cursors.Default
126:         Me.CommandTestConnection.RightToLeft = System.Windows.Forms.RightToLeft.No
127:         Me.CommandTestConnection.TabStop = True
128:         Me.CommandTestConnection.Name = "CommandTestConnection"
129:         Me.TextDatabasePassword.AutoSize = False
130:         Me.TextDatabasePassword.Size = New System.Drawing.Size(241, 25)
131:         Me.TextDatabasePassword.Location = New System.Drawing.Point(104, 80)
132:         Me.TextDatabasePassword.TabIndex = 7
133:         Me.ToolTip1.SetToolTip(Me.TextDatabasePassword, "The SQL Server database password")
134:         Me.TextDatabasePassword.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
135:         Me.TextDatabasePassword.AcceptsReturn = True
136:         Me.TextDatabasePassword.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
137:         Me.TextDatabasePassword.BackColor = System.Drawing.SystemColors.Window
138:         Me.TextDatabasePassword.CausesValidation = True
139:         Me.TextDatabasePassword.Enabled = True
140:         Me.TextDatabasePassword.ForeColor = System.Drawing.SystemColors.WindowText
141:         Me.TextDatabasePassword.HideSelection = True
142:         Me.TextDatabasePassword.ReadOnly = False
143:         Me.TextDatabasePassword.Maxlength = 0
144:         Me.TextDatabasePassword.Cursor = System.Windows.Forms.Cursors.IBeam
145:         Me.TextDatabasePassword.MultiLine = False
146:         Me.TextDatabasePassword.RightToLeft = System.Windows.Forms.RightToLeft.No
147:         Me.TextDatabasePassword.ScrollBars = System.Windows.Forms.ScrollBars.None
148:         Me.TextDatabasePassword.TabStop = True
149:         Me.TextDatabasePassword.Visible = True
150:         Me.TextDatabasePassword.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
151:         Me.TextDatabasePassword.Name = "TextDatabasePassword"
152:         Me.TextDatabaseUserName.AutoSize = False
153:         Me.TextDatabaseUserName.Size = New System.Drawing.Size(241, 25)
154:         Me.TextDatabaseUserName.Location = New System.Drawing.Point(104, 48)
155:         Me.TextDatabaseUserName.TabIndex = 5
156:         Me.ToolTip1.SetToolTip(Me.TextDatabaseUserName, "The SQL Server database login name")
157:         Me.TextDatabaseUserName.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
158:         Me.TextDatabaseUserName.AcceptsReturn = True
159:         Me.TextDatabaseUserName.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
160:         Me.TextDatabaseUserName.BackColor = System.Drawing.SystemColors.Window
161:         Me.TextDatabaseUserName.CausesValidation = True
162:         Me.TextDatabaseUserName.Enabled = True
163:         Me.TextDatabaseUserName.ForeColor = System.Drawing.SystemColors.WindowText
164:         Me.TextDatabaseUserName.HideSelection = True
165:         Me.TextDatabaseUserName.ReadOnly = False
166:         Me.TextDatabaseUserName.Maxlength = 0
167:         Me.TextDatabaseUserName.Cursor = System.Windows.Forms.Cursors.IBeam
168:         Me.TextDatabaseUserName.MultiLine = False
169:         Me.TextDatabaseUserName.RightToLeft = System.Windows.Forms.RightToLeft.No
170:         Me.TextDatabaseUserName.ScrollBars = System.Windows.Forms.ScrollBars.None
171:         Me.TextDatabaseUserName.TabStop = True
172:         Me.TextDatabaseUserName.Visible = True
173:         Me.TextDatabaseUserName.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
174:         Me.TextDatabaseUserName.Name = "TextDatabaseUserName"
175:         Me.TextDatabaseServer.AutoSize = False
176:         Me.TextDatabaseServer.Size = New System.Drawing.Size(241, 25)
177:         Me.TextDatabaseServer.Location = New System.Drawing.Point(104, 20)
178:         Me.TextDatabaseServer.TabIndex = 3
179:         Me.ToolTip1.SetToolTip(Me.TextDatabaseServer, "The name or IP address of the SQL Server")
180:         Me.TextDatabaseServer.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
181:         Me.TextDatabaseServer.AcceptsReturn = True
182:         Me.TextDatabaseServer.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
183:         Me.TextDatabaseServer.BackColor = System.Drawing.SystemColors.Window
184:         Me.TextDatabaseServer.CausesValidation = True
185:         Me.TextDatabaseServer.Enabled = True
186:         Me.TextDatabaseServer.ForeColor = System.Drawing.SystemColors.WindowText
187:         Me.TextDatabaseServer.HideSelection = True
188:         Me.TextDatabaseServer.ReadOnly = False
189:         Me.TextDatabaseServer.Maxlength = 0
190:         Me.TextDatabaseServer.Cursor = System.Windows.Forms.Cursors.IBeam
191:         Me.TextDatabaseServer.MultiLine = False
192:         Me.TextDatabaseServer.RightToLeft = System.Windows.Forms.RightToLeft.No
193:         Me.TextDatabaseServer.ScrollBars = System.Windows.Forms.ScrollBars.None
194:         Me.TextDatabaseServer.TabStop = True
195:         Me.TextDatabaseServer.Visible = True
196:         Me.TextDatabaseServer.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
197:         Me.TextDatabaseServer.Name = "TextDatabaseServer"
198:         Me.LabelPassword.Text = "Password:"
199:         Me.LabelPassword.Size = New System.Drawing.Size(89, 17)
200:         Me.LabelPassword.Location = New System.Drawing.Point(8, 84)
201:         Me.LabelPassword.TabIndex = 8
202:         Me.LabelPassword.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
203:         Me.LabelPassword.TextAlign = System.Drawing.ContentAlignment.TopLeft
204:         Me.LabelPassword.BackColor = System.Drawing.SystemColors.Control
205:         Me.LabelPassword.Enabled = True
206:         Me.LabelPassword.ForeColor = System.Drawing.SystemColors.ControlText
207:         Me.LabelPassword.Cursor = System.Windows.Forms.Cursors.Default
208:         Me.LabelPassword.RightToLeft = System.Windows.Forms.RightToLeft.No
209:         Me.LabelPassword.UseMnemonic = True
210:         Me.LabelPassword.Visible = True
211:         Me.LabelPassword.AutoSize = False
212:         Me.LabelPassword.BorderStyle = System.Windows.Forms.BorderStyle.None
213:         Me.LabelPassword.Name = "LabelPassword"
214:         Me.LabelUserName.Text = "User Name:"
215:         Me.LabelUserName.Size = New System.Drawing.Size(89, 17)
216:         Me.LabelUserName.Location = New System.Drawing.Point(8, 52)
217:         Me.LabelUserName.TabIndex = 6
218:         Me.LabelUserName.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
219:         Me.LabelUserName.TextAlign = System.Drawing.ContentAlignment.TopLeft
220:         Me.LabelUserName.BackColor = System.Drawing.SystemColors.Control
221:         Me.LabelUserName.Enabled = True
222:         Me.LabelUserName.ForeColor = System.Drawing.SystemColors.ControlText
223:         Me.LabelUserName.Cursor = System.Windows.Forms.Cursors.Default
224:         Me.LabelUserName.RightToLeft = System.Windows.Forms.RightToLeft.No
225:         Me.LabelUserName.UseMnemonic = True
226:         Me.LabelUserName.Visible = True
227:         Me.LabelUserName.AutoSize = False
228:         Me.LabelUserName.BorderStyle = System.Windows.Forms.BorderStyle.None
229:         Me.LabelUserName.Name = "LabelUserName"
230:         Me.LabelDatabaseServer.Text = "Database Server:"
231:         Me.LabelDatabaseServer.Size = New System.Drawing.Size(89, 17)
232:         Me.LabelDatabaseServer.Location = New System.Drawing.Point(8, 24)
233:         Me.LabelDatabaseServer.TabIndex = 4
234:         Me.LabelDatabaseServer.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
235:         Me.LabelDatabaseServer.TextAlign = System.Drawing.ContentAlignment.TopLeft
236:         Me.LabelDatabaseServer.BackColor = System.Drawing.SystemColors.Control
237:         Me.LabelDatabaseServer.Enabled = True
238:         Me.LabelDatabaseServer.ForeColor = System.Drawing.SystemColors.ControlText
239:         Me.LabelDatabaseServer.Cursor = System.Windows.Forms.Cursors.Default
240:         Me.LabelDatabaseServer.RightToLeft = System.Windows.Forms.RightToLeft.No
241:         Me.LabelDatabaseServer.UseMnemonic = True
242:         Me.LabelDatabaseServer.Visible = True
243:         Me.LabelDatabaseServer.AutoSize = False
244:         Me.LabelDatabaseServer.BorderStyle = System.Windows.Forms.BorderStyle.None
245:         Me.LabelDatabaseServer.Name = "LabelDatabaseServer"
246:         Me.CommandCancel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
247:         Me.CancelButton = Me.CommandCancel
248:         Me.CommandCancel.Text = "Cancel"
249:         Me.CommandCancel.Size = New System.Drawing.Size(73, 25)
250:         Me.CommandCancel.Location = New System.Drawing.Point(280, 168)
251:         Me.CommandCancel.TabIndex = 1
252:         Me.ToolTip1.SetToolTip(Me.CommandCancel, "Cancel changes")
253:         Me.CommandCancel.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
254:         Me.CommandCancel.BackColor = System.Drawing.SystemColors.Control
255:         Me.CommandCancel.CausesValidation = True
256:         Me.CommandCancel.Enabled = True
257:         Me.CommandCancel.ForeColor = System.Drawing.SystemColors.ControlText
258:         Me.CommandCancel.Cursor = System.Windows.Forms.Cursors.Default
259:         Me.CommandCancel.RightToLeft = System.Windows.Forms.RightToLeft.No
260:         Me.CommandCancel.TabStop = True
261:         Me.CommandCancel.Name = "CommandCancel"
262:         Me.CommandOK.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
263:         Me.CommandOK.Text = "OK"
264:         Me.CommandOK.Size = New System.Drawing.Size(73, 25)
265:         Me.CommandOK.Location = New System.Drawing.Point(200, 168)
266:         Me.CommandOK.TabIndex = 0
267:         Me.ToolTip1.SetToolTip(Me.CommandOK, "Save changes")
268:         Me.CommandOK.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
269:         Me.CommandOK.BackColor = System.Drawing.SystemColors.Control
270:         Me.CommandOK.CausesValidation = True
271:         Me.CommandOK.Enabled = True
272:         Me.CommandOK.ForeColor = System.Drawing.SystemColors.ControlText
273:         Me.CommandOK.Cursor = System.Windows.Forms.Cursors.Default
274:         Me.CommandOK.RightToLeft = System.Windows.Forms.RightToLeft.No
275:         Me.CommandOK.TabStop = True
276:         Me.CommandOK.Name = "CommandOK"
277:         Me.Controls.Add(CheckTrustedConnection)
278:         Me.Controls.Add(FrameEditDatabase)
279:         Me.Controls.Add(CommandCancel)
280:         Me.Controls.Add(CommandOK)
281:         Me.FrameEditDatabase.Controls.Add(CommandTestConnection)
282:         Me.FrameEditDatabase.Controls.Add(TextDatabasePassword)
283:         Me.FrameEditDatabase.Controls.Add(TextDatabaseUserName)
284:         Me.FrameEditDatabase.Controls.Add(TextDatabaseServer)
285:         Me.FrameEditDatabase.Controls.Add(LabelPassword)
286:         Me.FrameEditDatabase.Controls.Add(LabelUserName)
287:         Me.FrameEditDatabase.Controls.Add(LabelDatabaseServer)
288:     End Sub
289: #End Region  
290: #Region "Upgrade Support "
291:     Private Shared m_vb6FormDefInstance As FormConnection
292:     Private Shared m_InitializingDefInstance As Boolean
293:     Public Shared Property DefInstance() As FormConnection
294:         Get
295:             If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
296:                 m_InitializingDefInstance = True
297:                 m_vb6FormDefInstance = New FormConnection()
298:                 m_InitializingDefInstance = False
299:             End If
300:             DefInstance = m_vb6FormDefInstance
301:         End Get
302:         Set
303:             m_vb6FormDefInstance = Value
304:         End Set
305:     End Property
306: #End Region  
307:     Private SelectedDatabaseServer As String
308:     Private SelectedDatabaseUserName As String
309:     Private SelectedDatabasePassword As String
310:     Private SelectedConnectionID As Integer
311:     Private SelectedUseTrustedConnection As Boolean
312:     
313:     'UPGRADE_WARNING: Event CheckTrustedConnection.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2075"'  
314:     Private Sub CheckTrustedConnection_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CheckTrustedConnection.CheckStateChanged
315:         
316:         If CheckTrustedConnection.CheckState = System.Windows.Forms.CheckState.Checked Then
317:             TextDatabaseUserName.Enabled = False
318:             TextDatabasePassword.Enabled = False
319:             CheckTrustedConnection.CheckState = System.Windows.Forms.CheckState.Checked
320:         Else
321:             TextDatabaseUserName.Enabled = True
322:             TextDatabasePassword.Enabled = True
323:             CheckTrustedConnection.CheckState = System.Windows.Forms.CheckState.Unchecked
324:         End If
325:         
326:     End Sub
327:     
328:     Private Sub CommandCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandCancel.Click
329:         FormConnection.DefInstance.Visible = False
330:         FormConnection.DefInstance.Close()
331:     End Sub
332:     
333:     Private Sub CommandOK_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandOK.Click
334:         
335:         Dim DataStore As New DataStoreClass
336:         DataStore.SetConnectionString((ApplicationDataStoreConnectionString))
337:         
338:         Dim SQL As String
339:         Dim SQLResult As Boolean
340:         SelectedDatabaseServer = TextDatabaseServer.Text
341:         SelectedDatabaseServer = Replace(SelectedDatabaseServer, "'", "''")
342:         SelectedDatabaseUserName = TextDatabaseUserName.Text
343:         SelectedDatabaseUserName = Replace(SelectedDatabaseUserName, "'", "''")
344:         SelectedDatabasePassword = TextDatabasePassword.Text
345:         SelectedDatabasePassword = Replace(SelectedDatabasePassword, "'", "''")
346:         'UPGRADE_WARNING: Couldn't resolve default property of object ConnectionsDictionary(). Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'  
347:         SelectedConnectionID = ConnectionsDictionary(FormEditConnections.DefInstance.ListConnections.SelectedIndex)
348:         
349:         'Trusted connections do not require user credentials  
350:         If CheckTrustedConnection.CheckState Then
351:             SelectedDatabaseUserName = ""
352:             SelectedDatabasePassword = ""
353:         End If
354:         
355:         'Adding a new database  
356:         If CurrentAction = "ADD CONNECTION" Then
357:             SQL = "INSERT INTO t_Connections "
358:             SQL = SQL & "( "
359:             SQL = SQL & "DatabaseServer, "
360:             SQL = SQL & "DatabaseUserName, "
361:             SQL = SQL & "DatabasePassword, "
362:             SQL = SQL & "UseTrustedConnection "
363:             SQL = SQL & ") "
364:             SQL = SQL & "VALUES "
365:             SQL = SQL & "( "
366:             SQL = SQL & "'" & SelectedDatabaseServer & "', "
367:             SQL = SQL & "'" & SelectedDatabaseUserName & "', "
368:             SQL = SQL & "'" & SelectedDatabasePassword & "', "
369:             SQL = SQL & CheckTrustedConnection.CheckState
370:             SQL = SQL & ") "
371:             
372:             SQLResult = DataStore.ExecuteSQL(SQL)
373:             
374:             'Enable buttons on edit databases window and update window  
375:             FormEditConnections.DefInstance.CommandEditConnection.Enabled = True
376:             FormEditConnections.DefInstance.CommandDeleteConnection.Enabled = True
377:             Call FormEditConnections.DefInstance.UpdateFormSettings()
378:         End If
379:         
380:         If CurrentAction = "EDIT CONNECTION" Then
381:             SQL = "UPDATE t_Connections "
382:             SQL = SQL & "SET "
383:             SQL = SQL & "DatabaseServer = '" & SelectedDatabaseServer & "', "
384:             SQL = SQL & "DatabaseUserName = '" & SelectedDatabaseUserName & "', "
385:             SQL = SQL & "DatabasePassword = '" & SelectedDatabasePassword & "', "
386:             SQL = SQL & "UseTrustedConnection = " & CheckTrustedConnection.CheckState & " "
387:             SQL = SQL & "WHERE ConnectionID = " & SelectedConnectionID
388:             
389:             SQLResult = DataStore.ExecuteSQL(SQL)
390:         End If
391:         
392:         Call FormEditConnections.DefInstance.UpdateFormSettings()
393:         FormConnection.DefInstance.Visible = False
394:         FormConnection.DefInstance.Close()
395:         
396:     End Sub
397:     'Test the database connection  
398:     Private Sub CommandTestConnection_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandTestConnection.Click
399:         
400:         On Error Resume Next
401:         
402:         Dim SQLServerConnectionString As String
403:         Dim RS As New ADODB.Recordset
404:         Dim DataConnection As New ADODB.Connection
405:         Dim SQL As String
406:         Dim HasDatabaseConnectionError As Boolean
407:         Dim HasDatabaseSQLError As Boolean
408:         Dim DatabaseConnectionError As String
409:         Dim DataError As Object
410:         Dim Result As Integer
411:         
412:         If CheckTrustedConnection.CheckState Then
413:             
414:             SQLServerConnectionString = "Driver={SQL Server};Trusted_Connection=yes;"
415:             SQLServerConnectionString = SQLServerConnectionString & "Server=" & TextDatabaseServer.Text & ";"
416:             SQLServerConnectionString = SQLServerConnectionString & "Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;"
417:             SQLServerConnectionString = SQLServerConnectionString & ""
418:             
419:         Else
420:             
421:             SQLServerConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;"
422:             'SQLServerConnectionString = SQLServerConnectionString & "Initial Catalog=" & ConnectionDatabaseName & ";"  
423:             SQLServerConnectionString = SQLServerConnectionString & "Data Source=" & TextDatabaseServer.Text & ";"
424:             SQLServerConnectionString = SQLServerConnectionString & "Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;"
425:             SQLServerConnectionString = SQLServerConnectionString & "User Id=" & TextDatabaseUserName.Text & ";"
426:             SQLServerConnectionString = SQLServerConnectionString & "PASSWORD=" & TextDatabasePassword.Text & ";"
427:             SQLServerConnectionString = SQLServerConnectionString & ""
428:             
429:         End If
430:         
431:         DataConnection.ConnectionString = SQLServerConnectionString
432:         DataConnection.Open(SQLServerConnectionString)
433:         
434:         'Ensure database can be opened  
435:         If DataConnection.State = 0 Then
436:             'FormMain.UpdateStatus ("Cannot open the SQL Server database " & ConnectionDatabaseName)  
437:             
438:             DatabaseConnectionError = "Cannot open the SQL Server database due to the following: " & vbCrLf & vbCrLf
439:             'Call AppendToLogFile(CurrentLogFileName, "ERROR: Cannot open the SQL Server database " & ConnectionDatabaseName & vbCrLf)  
440:             
441:             If DataConnection.Errors.Count > 0 Then
442:                 For    Each DataError In DataConnection.Errors
443:                     
444:                     'UPGRADE_WARNING: Couldn't resolve default property of object DataError. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'  
445:                     DatabaseConnectionError = DatabaseConnectionError & "  " & DataError & vbCrLf
446:                     '        Call AppendToLogFile(CurrentLogFileName, vbTab & "ERROR: SQL Server error: " & DataError & vbCrLf)  
447:                     
448:                 Next DataError
449:             End If
450:             
451:             DatabaseConnectionError = DatabaseConnectionError & vbCrLf & "Please check that the database server name, username and password are correct."
452:             
453:             HasDatabaseConnectionError = True
454:         Else
455:             HasDatabaseConnectionError = False
456:         End If
457:         
458:         If HasDatabaseConnectionError Then
459:             
460:             Result = MsgBox(DatabaseConnectionError, MsgBoxStyle.Critical, ApplicationName)
461:             If Result = MsgBoxResult.OK Then Exit Sub
462:             
463:         Else
464:             
465:             Result = MsgBox("Connection test successful!", MsgBoxStyle.OKOnly, ApplicationName)
466:             If Result = MsgBoxResult.OK Then Exit Sub
467:             
468:         End If
469:         
470:         
471:     End Sub
472:     
473:     Private Sub FormConnection_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
474:         
475:         Dim DataStore As New DataStoreClass
476:         Dim SQL As String
477:         DataStore.SetConnectionString((ApplicationDataStoreConnectionString))
478:         Dim SelectedConnectionKey As Integer
479:         
480:         If CurrentAction = "EDIT CONNECTION" Then
481:             CommandOK.Text = "Update"
482:         End If
483:         
484:         If CurrentAction = "ADD CONNECTION" Then
485:             CommandOK.Text = "Add"
486:         End If
487:         
488:         
489:         If CurrentAction = "EDIT CONNECTION" Then
490:             SelectedConnectionKey = FormEditConnections.DefInstance.ListConnections.SelectedIndex
491:             'UPGRADE_WARNING: Couldn't resolve default property of object ConnectionsDictionary(). Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'  
492:             SelectedConnectionID = ConnectionsDictionary(SelectedConnectionKey)
493:             
494:             'Get connection database server  
495:             SQL = "SELECT DatabaseServer FROM t_Connections WHERE ConnectionID = " & SelectedConnectionID
496:             SelectedDatabaseServer = DataStore.ExecuteSQLReturnSingleValue(SQL, "DatabaseServer")
497:             TextDatabaseServer.Text = SelectedDatabaseServer
498:             
499:             'Get connection database username  
500:             SQL = "SELECT DatabaseUserName FROM t_Connections WHERE ConnectionID = " & SelectedConnectionID
501:             SelectedDatabaseUserName = DataStore.ExecuteSQLReturnSingleValue(SQL, "DatabaseUserName")
502:             TextDatabaseUserName.Text = SelectedDatabaseUserName
503:             
504:             'Get connection database password  
505:             SQL = "SELECT DatabasePassword FROM t_Connections WHERE ConnectionID = " & SelectedConnectionID
506:             SelectedDatabasePassword = DataStore.ExecuteSQLReturnSingleValue(SQL, "DatabasePassword")
507:             TextDatabasePassword.Text = SelectedDatabasePassword
508:             
509:             'Check to see if this is a trusted connection  
510:             SQL = "SELECT UseTrustedConnection FROM t_Connections WHERE ConnectionID = " & SelectedConnectionID
511:             SelectedUseTrustedConnection = CBool(DataStore.ExecuteSQLReturnSingleValue(SQL, "UseTrustedConnection"))
512:             
513:             If SelectedUseTrustedConnection Then
514:                 TextDatabaseUserName.Enabled = False
515:                 TextDatabasePassword.Enabled = False
516:                 CheckTrustedConnection.CheckState = System.Windows.Forms.CheckState.Checked
517:             Else
518:                 TextDatabaseUserName.Enabled = True
519:                 TextDatabasePassword.Enabled = True
520:                 CheckTrustedConnection.CheckState = System.Windows.Forms.CheckState.Unchecked
521:             End If
522:             
523:         End If
524:         
525:         
526:     End Sub
527: End Class