-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathsource.vb
More file actions
59 lines (47 loc) · 1.98 KB
/
Copy pathsource.vb
File metadata and controls
59 lines (47 loc) · 1.98 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
52
53
54
55
56
57
58
' This is the first code listing in the System.Data.Common.DbConnectionStringBuilder.
Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Imports System.Data.SqlClient
Module Module1
' <Snippet1>
Sub Main()
Dim builder As New DbConnectionStringBuilder()
builder.ConnectionString = "Data Source=c:\MyData\MyDb.mdb"
builder.Add("Provider", "Microsoft.Jet.Oledb.4.0")
' Set up row-level locking.
builder.Add("Jet OLEDB:Database Locking Mode", 1)
' Note that the DbConnectionStringBuilder class
' is database agnostic, and it's possible to
' build any type of connection string using
' this class.
' Notice that the ConnectionString property may have been
' formatted by the DbConnectionStringBuilder class.
Dim oledbConnect As New _
OleDbConnection(builder.ConnectionString)
Console.WriteLine(oledbConnect.ConnectionString)
' Use the same DbConnectionStringBuilder to create
' a SqlConnection object.
builder.Clear()
builder.Add("integrated security", True)
builder.Add("Initial Catalog", "AdventureWorks")
builder.Add("Data Source", "(local)")
Dim sqlConnect As New SqlConnection(builder.ConnectionString)
Console.WriteLine(sqlConnect.ConnectionString)
' Pass the DbConnectionStringBuilder an existing
' connection string, and you can retrieve and
' modify any of the elements.
builder.ConnectionString = "server=(local);initial catalog=AdventureWorks"
builder.Item("Server") = "."
' The Item property is the default for the class,
' and setting the Item property adds the value if
' necessary.
builder("Integrated Security") = True
Console.WriteLine(builder.ConnectionString)
Console.WriteLine("Press Enter to finish.")
Console.ReadLine()
End Sub
' </Snippet1>
End Module