

# Connecting to a Babelfish DB cluster
<a name="babelfish-connect"></a>

To connect to Babelfish, you connect to the endpoint of the Aurora PostgreSQL cluster running Babelfish. Your client can use one of the following client drivers compliant with TDS version 7.1 through 7.4:
+ Open Database Connectivity (ODBC)
+ OLE DB Driver/MSOLEDBSQL
+ Java Database Connectivity (JDBC) version 8.2.2 (mssql-jdbc-8.2.2) and higher
+ Microsoft SqlClient Data Provider for SQL Server
+ .NET Data Provider for SQL Server
+ SQL Server Native Client 11.0 (deprecated)
+ OLE DB Provider/SQLOLEDB (deprecated)

With Babelfish, you run the following:
+ SQL Server tools, applications, and syntax on the TDS port, by default port 1433.
+ PostgreSQL tools, applications, and syntax on the PostgreSQL port, by default port 5432.

To learn more about connecting to Aurora PostgreSQL in general, see [Connecting to an Amazon Aurora PostgreSQL DB cluster](Aurora.Connecting.md#Aurora.Connecting.AuroraPostgreSQL). 

**Note**  
Third-party developer tools using the SQL Server OLEDB provider to access metadata aren't supported. We recommend you to use SQL Server JDBC, ODBC, or SQL Native client connections for these tools.

Starting with Babelfish version 5.1.0, end-to-end connection encryption is enforced by default. To ensure continued connectivity:
+ Configure SSL/TLS encryption for your connections. For more information, see [Using SSL/TLS to encrypt a connection to a DB cluster](UsingWithRDS.SSL.md).
+ Import the required certificates on your client computers. For more information, see [Using SSL with a Microsoft SQL Server DB instance](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Concepts.General.SSL.Using.html).

If you want to continue using the encryption settings from a previous version of Babelfish (prior to version 5.1.0), you can set the `rds.force_ssl` parameter to `0` in your DB cluster parameter group.

**Topics**
+ [

## Finding the writer endpoint and port number
](#babelfish-connect-endpoint)
+ [

# Creating C\$1 or JDBC client connections to Babelfish
](babelfish-connect-configure.md)
+ [

# Using a SQL Server client to connect to your DB cluster
](babelfish-connect-sqlserver.md)
+ [

# Using a PostgreSQL client to connect to your DB cluster
](babelfish-connect-PostgreSQL.md)

## Finding the writer endpoint and port number
<a name="babelfish-connect-endpoint"></a>

To connect to your Babelfish DB cluster, you use the endpoint associated with the DB cluster's writer (primary) instance. The instance must have a status of **Available**. It can take up to 20 minutes for the instances to be available after creating the Babelfish for Aurora PostgreSQL DB cluster.

**To find your database endpoint**

1. Open the console for Babelfish.

1. Choose **Databases** from the navigation pane. 

1. Choose your Babelfish for Aurora PostgreSQL DB cluster from those listed to see its details. 

1. On the **Connectivity & security** tab, note the available cluster **Endpoints** values. Use the cluster endpoint for the writer instance in your connection strings for any applications that perform database write or read operations.  
![\[\]](http://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/images/Babelfish-database-endpoint.png)

For more information about Aurora DB cluster details, see [Creating an Amazon Aurora DB cluster](Aurora.CreateInstance.md).

# Creating C\$1 or JDBC client connections to Babelfish
<a name="babelfish-connect-configure"></a>

In the following you can find some examples of using C\$1 and JDBC classes to connect to an Babelfish for Aurora PostgreSQL. 

**Example : Using C\$1 code to connect to a DB cluster**  

```
string dataSource = 'babelfishServer_11_24';

//Create connection
connectionString = @"Data Source=" + dataSource
    +";Initial Catalog=your-DB-name"
    +";User ID=user-id;Password=password";
					
// [optional] To validate server certificate during TLS/SSL connection
connectionString = connectionString + ";ServerCertificate=/path/to/certificate.pem";					

SqlConnection cnn = new SqlConnection(connectionString);
cnn.Open();
```

**Example : Using generic JDBC API classes and interfaces to connect to a DB cluster**  

```
String dbServer = 
   "database-babelfish.cluster-123abc456def.us-east-1-rds.amazonaws.com";
String connectionUrl = "jdbc:sqlserver://" + dbServer + ":1433;" +
    "databaseName=your-DB-name;user=user-id;password=password";

// [optional] To validate server certificate during TLS/SSL connection
connectionUrl = connectionUrl + ";serverCertificate=/path/to/certificate.pem";

// Load the SQL Server JDBC driver and establish the connection.
System.out.print("Connecting Babelfish Server ... ");
Connection cnn = DriverManager.getConnection(connectionUrl);
```

**Example : Using SQL Server-specific JDBC classes and interfaces to connect to a DB cluster**  

```
// Create datasource.
SQLServerDataSource ds = new SQLServerDataSource();
ds.setUser("user-id");
ds.setPassword("password");
String babelfishServer = 
   "database-babelfish.cluster-123abc456def.us-east-1-rds.amazonaws.com";

ds.setServerName(babelfishServer);
ds.setPortNumber(1433);
ds.setDatabaseName("your-DB-name");

// [optional] To validate server certificate during TLS/SSL connection
ds.setServerCertificate("/path/to/certificate.pem"); 

Connection con = ds.getConnection();
```

**Important**  
Ensure the certificate matches the Certificate Authority shown in your DB cluster configuration on the AWS Management Console.

# Using a SQL Server client to connect to your DB cluster
<a name="babelfish-connect-sqlserver"></a>

You can use a SQL Server client to connect with Babelfish on the TDS port. As of Babelfish 2.1.0 and higher releases, you can use the SSMS Object Explorer or the SSMS Query Editor to connect to your Babelfish cluster. 

**Limitations**
+ Babelfish doesn't support MARS (Multiple Active Result Sets). Be sure that any client applications that you use to connect to Babelfish aren't set to use MARS. 

For more information about interoperability and behavioral differences between SQL Server and Babelfish, see [Differences between Babelfish for Aurora PostgreSQL and SQL Server](babelfish-compatibility.md).

## Using sqlcmd to connect to the DB cluster
<a name="babelfish-connect-sqlcmd"></a>

You can connect to and interact with an Aurora PostgreSQL DB cluster that supports Babelfish by SQL Server `sqlcmd` command line client. Use the following command to connect.

```
sqlcmd -S endpoint,port -U login-id -P password -d your-DB-name
```

The options are as follows:
+ `-S` is the endpoint and (optional) TDS port of the DB cluster.
+ `-U` is the login name of the user.
+ `-P` is the password associated with the user.
+ `-d` is the name of your Babelfish database.

After connecting, you can use many of the same commands that you use with SQL Server. For some examples, see [Getting information from the Babelfish system catalog](babelfish-query-database.md).

## Using SSMS to connect to the DB cluster
<a name="babelfish-connect-SSMS"></a>

You can connect to an Aurora PostgreSQL DB cluster running Babelfish by using Microsoft SQL Server Management Studio (SSMS). SSMS includes a variety of tools, including the SQL Server Import amd Export Wizard discussed in [Migrating a SQL Server database to Babelfish for Aurora PostgreSQL](babelfish-migration.md). For more information about SSMS, see [ Download SQL Server Management Studio (SSMS)](https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16) in the Microsoft documentation. To configure SSL/TLS, see [Using SSL with a Microsoft SQL Server DB instance](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Concepts.General.SSL.Using.html). 

**Note**  
SSMS version 19.2 and later requires Babelfish version 3.5.0 (Aurora PostgreSQL 15.6) or higher to display databases in Object Explorer.

**To connect to your Babelfish database with SSMS**

1. Start SSMS.

1. Open the **Connect to Server** dialog box. To continue with the connection, do one of the following:
   + Choose **New Query**.
   + If the Query Editor is open, choose **Query**, **Connection**, **Connect**.

1. Provide the following information for your database:

   1. For **Server type**, choose **Database Engine**.

   1. For **Server name**, enter the DNS name. For example, your server name should look similar to the following.

      ```
      cluster-name.cluster-555555555555.aws-region.rds.amazonaws.com,1433
      ```

   1. For **Authentication**, choose **SQL Server Authentication**.

   1. For **Login**, enter the user name that you chose when you created your database.

   1. For **Password**, enter the password that you chose when you created your database.  
![\[\]](http://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/images/Babelfish-SSMS-connect-database1.png)
**Note**  
Babelfish 5.1.0 and later versions use TLS by default. You can either install the root CA certificate on the client or select the **Trust server certificate** checkbox on the Login tab.

1. (Optional) Choose **Options**, and then choose the **Connection Properties** tab.  
![\[\]](http://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/images/Babelfish-SSMS-connect-database2.png)

1. (Optional) For **Connect to database**, specify the name of the migrated SQL Server database to connect to, and choose **Connect**.

   If a message appears indicating that SSMS can't apply connection strings, choose **OK**.

   If you are having trouble connecting to Babelfish, see [Connection failure](babelfish-troubleshooting.md#babelfish-troubleshooting-connectivity).

   For more information about SQL Server connection issues, see [Troubleshooting connections to your SQL Server DB instance](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToMicrosoftSQLServerInstance.html#USER_ConnectToMicrosoftSQLServerInstance.Troubleshooting) in the *Amazon RDS User Guide*.

# Using a PostgreSQL client to connect to your DB cluster
<a name="babelfish-connect-PostgreSQL"></a>

You can use a PostgreSQL client to connect to Babelfish on the PostgreSQL port. Starting with version 5.1.0, the Babelfish server enforces end-to-end connection encryption by default. Update your application to work with SSL/TLS certificates. For more information about configuring SSL/TLS certificates, see [Securing Aurora PostgreSQL data with SSL/TLS](AuroraPostgreSQL.Security.md#AuroraPostgreSQL.Security.SSL).

## Using psql to connect to the DB cluster
<a name="babelfish-connect-psql"></a>

You can download the PostgreSQL client from the [PostgreSQL](https://www.postgresql.org/download/) website. Follow the instructions specific to your operating system version to install psql.

You can query an Aurora PostgreSQL DB cluster that supports Babelfish with the `psql` command line client. When connecting, use the PostgreSQL port (by default, port 5432). Typically, you don't need to specify the port number unless you changed it from the default. Use the following command to connect to Babelfish from the `psql` client:

```
psql -h bfish-db.cluster-123456789012.aws-region.rds.amazonaws.com
-p 5432 -U postgres -d babelfish_db
```

The parameters are as follows:
+ `-h` – The host name of the DB cluster (cluster endpoint) that you want to access.
+ `-p` – The PostgreSQL port number used to connect to your DB instance.
+ `-d` – The database that you want to connect to. The default is `babelfish_db`.
+ `-U` – The database user account that you want to access. (The example shows the default master username.)

When you run a SQL command on the psql client, you end the command with a semicolon. For example, the following SQL command queries the [pg\$1tables system view](https://www.postgresql.org/docs/current/view-pg-tables.html) to return information about each table in the database.

`SELECT * FROM pg_tables;`

The psql client also has a set of built-in metacommands. A *metacommand* is a shortcut that adjusts formatting or provides a shortcut that returns meta-data in an easy-to-use format. For example, the following metacommand returns similar information to the previous SQL command:

`\d`

Metacommands don't need to be terminated with a semicolon (;).

To exit the psql client, enter `\q`.

For more information about using the psql client to query an Aurora PostgreSQL cluster, see [the PostgreSQL documentation](https://www.postgresql.org/docs/14/app-psql.html).

## Using pgAdmin to connect to the DB cluster
<a name="babelfish-connect-pgadmin"></a>

You can use the pgAdmin client to access your data in native PostgreSQL dialect. 

**To connect to the cluster with the pgAdmin client**

1. Download and install the pgAdmin client from the [pgAdmin website](https://www.pgadmin.org/).

1. Open the client and authenticate with pgAdmin.

1. Open the context (right-click) menu for **Servers**, and then choose **Create**, **Server**.  
![\[\]](http://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/images/pgAdmin1.png)

1. Enter information in the **Create - Server** dialog box. 

   On the **Connection** tab, add the Aurora PostgreSQL cluster address for **Host** and the PostgreSQL port number (by default, 5432) for **Port**. Provide authentication details, and choose **Save**.  
![\[\]](http://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/images/pgAdmin2.png)

After connecting, you can use pgAdmin functionality to monitor and manage your Aurora PostgreSQL cluster on the PostgreSQL port.

![\[\]](http://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/images/pgAdmin3.png)


To learn more, see the [pgAdmin](https://www.pgadmin.org/) web page.