-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathsource.vb
More file actions
51 lines (44 loc) · 1.58 KB
/
Copy pathsource.vb
File metadata and controls
51 lines (44 loc) · 1.58 KB
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
Imports System.Data
Imports System.Data.OleDb
Module Module1
Sub Main()
Dim x As String = "Provider=SQLOLEDB;Data Source=dschwart3;Initial Catalog=AdventureWorks;" _
& "Integrated Security=SSPI"
OpenConnection(x)
ChangeDatabaseConnection(x)
Console.ReadLine()
End Sub
' <Snippet1>
Public Sub OpenConnection(ByVal connectionString As String)
Using connection As New OleDbConnection(connectionString)
Try
connection.Open()
Console.WriteLine("Server Version: {0} Database: {1}", _
connection.ServerVersion, connection.Database)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
End Sub
' </Snippet1>
' <Snippet2>
Public Sub ChangeDatabaseConnection(ByVal connectionString As String)
Using connection As New OleDbConnection(connectionString)
Try
connection.Open()
Console.WriteLine("Server Version: {0} Database: {1}", _
connection.ServerVersion, connection.Database)
connection.ChangeDatabase("Northwind")
Console.WriteLine("Server Version: {0} Database: {1}", _
connection.ServerVersion, connection.Database)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
End Sub
' </Snippet2>
End Module