Connection strings for SQL Server 2000, 7.0
Microsoft OLE DB Provider for SQL Server
.NET Framework Data Provider for OLE DB(OleDbConnection)
Microsoft SQL Server ODBC Driver
SQL Server Native Client 10.0 OLE DB Provider
SQL Native Client 9.0 OLE DB provider
SQL Server Native Client 10.0 ODBC Driver
SQL Native Client 9.0 ODBC Driver
.NET Framework Data Provider for ODBC(OdbcConnection)
SQLXML 3.0 OLEDB Provider
MSDataShape
.NET Framework Data Provider for SQL Server
Usage System.Data.SqlClient.SqlConnection
Manufacturer Microsoft
Standard Security
Standard Security alternative syntax
This connection string produces the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.
Trusted Connection
Trusted Connection alternative syntax
This connection string produce the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.
Use serverName\instanceName as Data Source to use a specific SQL Server instance. Please note that the multiple SQL Server instances feature is available only from SQL Server version 2000 and not in any previous versions.
Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Trusted Connection from a CE device
Often a Windows CE device is not authenticated and logged in to a domain. To use SSPI or trusted connection / authentication from a CE device, use this connection string.
Note that this will only work on a CE device.
Read more about connecting to SQL Server from CE devices here
Connect via an IP address
DBMSSOCN=TCP/IP. This is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433 is the default port for SQL Server.
Specifying packet size
By default, the Microsoft .NET Framework Data Provider for SQL Server sets the network packet size to 8192 bytes. This might however not be optimal, try to set this value to 4096 instead.
Microsoft OLE DB Provider for SQL Server
Usage Provider=sqloledb
Manufacturer Microsoft
Standard Security
Trusted connection
Use serverName\instanceName as Data Source to use a specific SQL Server instance. Please note that the multiple SQL Server instances feature is available only from SQL Server version 2000 and not in any previous versions.
Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Prompt for username and password
This one is a bit tricky. First set the connection object's Provider property to "sqloledb". Thereafter set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
oConn.Properties("Prompt") = adPromptAlways
Data Source=myServerAddress;Initial Catalog=myDataBase;
Connect via an IP address
DBMSSOCN=TCP/IP. This is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433 is the default port for SQL Server.
Disable connection pooling
This one is usefull when receving errors "sp_setapprole was not invoked correctly." (7.0) or "General network error. Check your network documentation" (2000) when connecting using an application role enabled connection. Application pooling (or OLE DB resource pooling) is on by default. Disabling it can help on this error.
.NET Framework Data Provider for OLE DB
Usage System.Data.OleDb.OleDbConnection
Manufacturer Microsoft
Bridging to OLE DB Provider for SQL Server
This is just one connection string sample for the wrapping OleDbConnection class that calls the underlying OLEDB provider. See respective OLE DB provider for more connection strings to use with this class.
Microsoft SQL Server ODBC Driver
Usage Driver={SQL Server}
Manufacturer Microsoft
Standard Security
Trusted connection
Prompt for username and password
This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;
SQL Server Native Client 10.0 OLE DB Provider
Usage Provider=SQLNCLI10
Manufacturer Microsoft
Standard security
Note that the SQL Server Native Client OLE DB Provider does not support SQL Server 7.0.
Trusted connection
Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"
Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Prompt for username and password
This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
oConn.Open "Provider=SQLNCLI10;Server=myServerAddress;DataBase=myDataBase;
Encrypt data sent over network
SQL Native Client 9.0 OLE DB provider
Usage Provider=SQLNCLI
Manufacturer Microsoft
Standard security
Note that the SQL Server Native Client OLE DB Provider does not support SQL Server 7.0.
Trusted connection
Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"
Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Prompt for username and password
This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
oConn.Open "Provider=SQLNCLI;Server=myServerAddress;DataBase=myDataBase;
Encrypt data sent over network
SQL Server Native Client 10.0 ODBC Driver
Usage Driver={SQL Server Native Client 10.0}
Manufacturer Microsoft
Standard security
Trusted Connection
Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"
Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Prompt for username and password
This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;
Encrypt data sent over network
SQL Native Client 9.0 ODBC Driver
Usage Driver={SQL Native Client}
Manufacturer Microsoft
Standard security
Trusted Connection
Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"
Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Prompt for username and password
This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
Encrypt data sent over network
.NET Framework Data Provider for ODBC
Usage System.Data.Odbc.OdbcConnection
Manufacturer Microsoft
Bridging to SQL Native Client 10.0 ODBC Driver
This is just one connection string sample for the wrapping OdbcConnection class that calls the underlying ODBC Driver. See respective ODBC driver for more connection strings to use with this class.
SQLXML 3.0 OLEDB Provider
Usage Provider=SQLXMLOLEDB.3.0;Data Provider=sqloledb
Manufacturer Microsoft
Using SQL Server Ole Db
The SQLXML version 3.0 restricts the data provider to SQLOLEDB only.
MSDataShape
Usage Provider=MSDataShape;Data Provider=providername
Manufacturer Microsoft
