Connecting to JDBC connections (SQL) with multiple instances

Overview

When creating a connection to a SQL Server through Studio, by default, you can only connect to a single instance of the database server through the JDBC string.

 

The general form of the connection URL is:

jdbc:sqlserver://[serverName[\instanceName][portNumber]][;property=value[;property=value]]

 

where:

  • jdbc:sqlserver:// (Required) is known as the sub-protocol and is constant.
  • serverName (Optional) is the address of the server to connect to, which could be a DNS or IP address, or it could be localhost or 127.0.0.1 for the local computer. If not specified in the connection URL, the server name must be specified in the properties collection.
  • instanceName (Optional) is the instance to connect to on serverName. If not specified, a connection to the default instance is made.
  • portNumber (Optional) is the port to connect to on serverName. The default is 1433. If you are using the default, you do not have to specify the port, nor it's preceding ':', in the URL.
  • property (Optional) is one or more option connection properties.

 

Connection examples

Connect to the default database on the local computer by using a username and password, for example:

jdbc:sqlserver://localhost;user=MyUserName;password=*****;

kb_2_sql.png

 

Named and multiple SQL Server instances

SQL Server allows for the installation of multiple database instances per server. A specific name identifies each instance. To connect to a named instance of SQL Server, you can specify the port number of the named instance (preferred), or you can specify the instance name as a JDBC URL property or a data source property. If no instance name or port number property is specified, a connection to the default instance is created.

 

In addition to multiple SQL Server instances, you need to set one of the following properties:

 

To use a port number, enter the following:

jdbc:sqlserver://localhost:1433;integratedSecurity=true;<more properties as required>;

 

To use a JDBC URL property, enter the following:

jdbc:sqlserver://localhost;instanceName=instance1;integratedSecurity=true;<more properties as required>;

Version history
Revision #:
10 of 10
Last update:
‎04-13-2019 12:16 PM
Updated by: