Microsoft OLE DB Provider for SQL Server connection strings

SQL Server 2000

Trusted connection

Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

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.

Using a non-standard port

If your SQL Server listens on a non-default port you can specify that using the servername,xxxx syntax (note the comma, it's not a colon).

Provider=sqloledb;Server=myServerName,myPortNumber;Database=myDataBase;User Id=myUsername;Password=myPassword;

The default SQL Server port is 1433 and there is no need to specify that in the connection string.

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.Provider = "sqloledb"
oConn.Properties("Prompt") = adPromptAlways

oConn.Open "Data Source=myServerAddress;Initial Catalog=myDataBase;"

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.

Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;OLE DB Services=-2;

SQL Server 7.0

Trusted connection

Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

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.

Using a non-standard port

If your SQL Server listens on a non-default port you can specify that using the servername,xxxx syntax (note the comma, it's not a colon).

Provider=sqloledb;Server=myServerName,myPortNumber;Database=myDataBase;User Id=myUsername;Password=myPassword;

The default SQL Server port is 1433 and there is no need to specify that in the connection string.

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.Provider = "sqloledb"
oConn.Properties("Prompt") = adPromptAlways

oConn.Open "Data Source=myServerAddress;Initial Catalog=myDataBase;"

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.

Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;OLE DB Services=-2;