Sunday, October 12, 2008

How do I connect to SQL Server on a port other than 1433

Sometimes an added measure of security can be achieved by using ports other than the defaults for server software. SQL Server allows you to specify which port you want it to run on; the default is 1433. Provided you can access your SQL Server through TCP/IP, the following connection string should help you connect to a different port (this example uses port 1510 on the local machine):

cst = "Provider=SQLOLEDB;" & _
"Data Source=[x.x.x.x],[port number];" & _
"Initial Catalog=[dbname];" & _
"Network=DBMSSOCN;" & _
"User Id=[uid];" & _

set conn = CreateObject("ADODB.Connection") cst

Notice that the IP address and port number are separated by a comma, and that TCP/IP is 'forced' by adding network=DBMSSOCN.

No comments: