You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This topic discusses how you can create a connection to a [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] database.
@@ -30,34 +32,40 @@ See [DSN and Connection String Keywords and Attributes](../dsn-connection-string
30
32
31
33
The value passed to the **Driver** keyword can be one of the following:
32
34
33
-
-The name you used when you installed the driver.
35
+
- The name you used when you installed the driver.
34
36
35
-
-The path to the driver library, which was specified in the template .ini file used to install the driver.
37
+
- The path to the driver library, which was specified in the template .ini file used to install the driver.
36
38
37
-
To create a DSN, create (if necessary) and edit the file **~/.odbc.ini** (`.odbc.ini` in your home directory) for a User DSN only accessible to the current user, or `/etc/odbc.ini` for a System DSN (administrative privileges required.) The following is a sample file that shows the minimal required entries for a DSN:
39
+
DSNs are optional. You can use a DSN to define connection string keywords under a `DSN` name that you can then reference in the connection string. To create a DSN, create (if necessary) and edit the file **~/.odbc.ini** (`.odbc.ini` in your home directory) for a User DSN only accessible to the current user, or `/etc/odbc.ini` for a System DSN (administrative privileges required.) The following is a sample file that shows the minimal required entries for a DSN:
38
40
39
-
```
41
+
```ini
42
+
# [DSN name]
40
43
[MSSQLTest]
41
-
Driver = ODBC Driver 13 for SQL Server
42
-
Server = [protocol:]server[,port]
43
-
#
44
+
Driver = ODBC Driver 17 for SQL Server
45
+
# Server = [protocol:]server[,port]
46
+
Server = tcp:localhost,1433
47
+
#
44
48
# Note:
45
49
# Port is not a valid keyword in the odbc.ini file
46
50
# for the Microsoft ODBC driver on Linux or macOS
47
51
#
48
52
```
49
53
54
+
To connect using the above DSN in a connection string, you would specify the `DSN` keyword like: `DSN=MSSQLTest;UID=my_username;PWD=my_password`
55
+
The above connection string would be the equivalent of specifying a connection string without the `DSN` keyword like: `Driver=ODBC Driver 17 for SQL Server;Server=tcp:localhost,1433;UID=my_username;PWD=my_password`
56
+
50
57
You can optionally specify the protocol and port to connect to the server. For example, **Server=tcp:**_servername_**,12345**. Note that the only protocol supported by the Linux and macOS drivers is `tcp`.
51
58
52
59
To connect to a named instance on a static port, use <b>Server=</b>*servername*,**port_number**. Connecting to a dynamic port is not supported before version 17.4.
53
60
54
61
Alternatively, you can add the DSN information to a template file, and execute the following command to add it to `~/.odbc.ini` :
55
62
-**odbcinst -i -s -f**_template_file_
56
-
63
+
57
64
You can verify that your driver is working by using `isql` to test the connection, or you can use this command:
58
65
-**bcp master.INFORMATION_SCHEMA.TABLES out OutFile.dat -S <server> -U <name> -P <password>**
59
66
60
67
## Using TLS/SSL
68
+
61
69
You can use Transport Layer Security (TLS), previously known as Secure Sockets Layer (SSL), to encrypt connections to [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)]. TLS protects [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] user names and passwords over the network. TLS also verifies the identity of the server to protect against man-in-the-middle (MITM) attacks.
62
70
63
71
Enabling encryption increases security at the expense of performance.
@@ -73,7 +81,7 @@ Regardless of the settings for **Encrypt** and **TrustServerCertificate**, the s
73
81
74
82
By default, encrypted connections always verify the server's certificate. However, if you connect to a server that has a self-signed certificate, also add the `TrustServerCertificate` option to bypass checking the certificate against the list of trusted certificate authorities:
75
83
76
-
```
84
+
```
77
85
Driver={ODBC Driver 13 for SQL Server};Server=ServerNameHere;Encrypt=YES;TrustServerCertificate=YES
0 commit comments