All Products
Search
Document Center

ApsaraDB RDS:Connect to an RDS for SQL Server instance

Last Updated:Mar 30, 2026

After you complete the initial configuration for an ApsaraDB RDS for SQL Server instance, connect to it using Data Management (DMS), SQL Server Management Studio (SSMS), or Java Database Connectivity (JDBC). This topic covers all three methods.

Prerequisites

Before you begin, make sure you have:

For internal network connections from an Elastic Compute Service (ECS) instance, the ECS instance and the RDS instance must be in the same virtual private cloud (VPC) in the same region, and the private IP address of the ECS instance must be in the whitelist. For connections from an on-premises device, add the public IP address of the device to the whitelist.

Before you connect

Verify the following before starting any connection method:

  1. The IP address of your client (ECS instance or on-premises device) is added to the instance's IP address whitelist.

  2. For SSMS or JDBC connections from outside Alibaba Cloud's internal network, a public endpoint is applied for the instance.

Find your endpoint

All connection methods require the instance endpoint and port. To find them:

  1. Go to the Instances page. In the top navigation bar, select the region where the instance resides. Click the instance ID.

  2. On the instance details page, locate the endpoint and port number. For detailed steps, see View and change the endpoints and port numbers.

Endpoint type When to use
Internal endpoint Connecting from an ECS instance in the same VPC and region
Public endpoint Connecting from an on-premises device or from outside Alibaba Cloud's internal network. Apply for a public endpoint first if you haven't done so. See Apply for or release a public endpoint.

Connect using DMS

DMS is a web-based database management platform. It requires no client installation and no manual whitelist configuration for the RDS instance itself.

  1. Go to the Instances page. Select the region in the top navigation bar, then find the instance and click its ID.

  2. Click Log On to Database.

    image..png

  3. In the Log on to Database Instance dialog box, configure the login parameters and click Login.

    • Access Mode: Select Account + password login.

    • Database Account and Database Password: Enter your account credentials. This example uses the privileged account testuser.

    • Control Mode: Select Flexible Management for trial use. This mode is free of charge. Stable Change and Security Collaboration modes provide more features but generate fees.

    image

  4. In the left-side navigation pane of the DMS console, choose Database Instances > Instances Connected to view your databases. In this example, the database dbtest is displayed. Double-click a database to open it.

    If the instance exists but the database is not listed under Instances Connected, check the following: - The login account lacks permissions for that database. Go to the Accounts page of the RDS instance, find the account, and click Change Permissions in the Actions column to grant the required permissions. - The database metadata is not synchronized. Hover over the RDS instance name and click the image icon to the right to refresh.

    image

  5. Run queries and manage data on the SQL Console tab.

Connect using SSMS

SSMS is a GUI client for managing SQL Server databases. It supports connections to RDS instances, on-premises SQL Server instances, and SQL Server instances in other clouds.

Before connecting with SSMS:

  • Download the latest version of SSMS to ensure compatibility with all SQL Server versions. See Download SQL Server Management Studio (SSMS).

  • Apply for a public endpoint and add your on-premises IP address to the whitelist.

This example uses SSMS 19.0.

  1. Start SSMS.

  2. Choose Connect > Database Engine.

  3. In the Connect to Server dialog box, enter the following parameters:

    Parameter Example value Description
    Server name rm-2ze****.rds.aliyuncs.com,1433 The public endpoint and port, separated by a comma (,). See Find your endpoint.
    Authentication SQL Server Authentication The authentication method.
    Username testuser The RDS account username.
    Password Test_pw123 The RDS account password.
  4. Click Connect.

After a successful connection, the connected instance and its databases appear in the left pane of SSMS.

Connect using Java (JDBC)

Use JDBC to connect a Java application to the RDS instance programmatically.

Add the IP address of the environment where the application runs to the instance's IP address whitelist before connecting. See Configure an IP address whitelist.

Step 1: Add the JDBC driver

Option A: Add the Maven dependency

Add the following to the pom.xml file of your Maven project. Select the version that matches your Java version — for example, mssql-jdbc-12.2.0.jre8.jar works with Java 8 or later. For historical versions, see the official repository.

<dependency>
  <groupId>com.microsoft.sqlserver</groupId>
  <artifactId>mssql-jdbc</artifactId>
  <version>12.2.0.jre8</version>
</dependency>

After adding the dependency, click the Maven refresh icon to download it automatically.

imageimageimage

Option B: Download the driver manually

  1. Download the JDBC driver that matches your Java version from Download Microsoft JDBC Driver for SQL Server.

  2. Extract the package and add the JAR file (such as sqljdbc4.jar or sqljdbc.jar) to your project classpath. The following screenshots show how to add the JAR in IntelliJ IDEA.

    image

    image

    image

Step 2: Connect with sample code

Store credentials in environment variables rather than hardcoding them. Replace the placeholders in the connection URL with your actual values. For endpoint details, see View and change the endpoints and port numbers.

  • Use the internal endpoint if the application runs on an ECS instance in the same VPC as the RDS instance.

  • Use the public endpoint if the application runs on an on-premises device or in another environment.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

public class SqlServerConnection {

    public static void main(String[] args) {
        // Replace <endpoint> and <port> with the internal or public endpoint of your RDS instance.
        // Replace <YourDatabaseName> with the target database name.
        String url = "jdbc:sqlserver://<endpoint>:<port>;"
                + "database=<YourDatabaseName>;"
                + "encrypt=true;"
                + "trustServerCertificate=true;"
                + "loginTimeout=30;";

        // Load credentials from environment variables to avoid hardcoding sensitive information.
        String username = System.getenv("RDS_USERNAME");
        String password = System.getenv("RDS_PASSWORD");

        Connection connection = null;

        try {
            // Load the JDBC driver.
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            // Establish the connection.
            connection = DriverManager.getConnection(url, username, password);
            System.out.println("Connection succeeded!");

            // Execute a sample query. Replace <YourTableName> and column names with actual values.
            Statement statement = connection.createStatement();
            String sql = "SELECT TOP 10 * FROM <YourTableName>";
            ResultSet resultSet = statement.executeQuery(sql);

            while (resultSet.next()) {
                System.out.println("Column 1: " + resultSet.getString("<YourColumnName1>"));
                System.out.println("Column 2: " + resultSet.getString("<YourColumnName2>"));
            }

            resultSet.close();
            statement.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Replace the following placeholders before running the code:

Placeholder Description Example
<endpoint> Internal or public endpoint of the RDS instance rm-2vc367d081200******.mssql.cn-chengdu.rds.aliyuncs.com
<port> Port number 1433
<YourDatabaseName> Target database name mydb
<YourTableName> Table to query orders
<YourColumnName1>, <YourColumnName2> Columns to retrieve id, name

Set the environment variables before running:

export RDS_USERNAME=<your-username>
export RDS_PASSWORD=<your-password>

Step 3: Verify the connection

Compile and run SqlServerConnection.java. If the configuration is correct, the output shows:

Connection succeeded!
image

FAQ

My public IP address keeps changing. How do I maintain whitelist access?

Add the CIDR block that covers your IP range to the whitelist, rather than a single IP. For guidance, see Configure an IP address whitelist and How do I obtain the public IP address of an external server or a client?

Important

0.0.0.0/0 allows access from any IP address. If you add it temporarily for testing, remove or replace it immediately after the test.

How do I access my RDS instance from Function Compute?

Install third-party dependencies in your Function Compute function, then use the built-in modules provided by those dependencies to query the instance. See Install third-party dependencies on Function Compute.

I logged in with DMS but my database isn't listed under Instances Connected. Why?

Two things to check: the login account may lack permissions for that database, or the database metadata may not be synchronized. Go to the Accounts page of the RDS instance, find the account, and click Change Permissions in the Actions column to grant access. If permissions are correct, hover over the instance name and click the image icon to refresh database metadata.

I can't connect to my RDS instance from my computer using SSMS. What should I check?

Make sure you have applied for a public endpoint for the instance — the internal endpoint is not reachable from outside Alibaba Cloud's internal network. You are not charged for the Internet traffic that is generated to apply for the public endpoint and for subsequent usage. See Apply for or release a public endpoint.

image

Also confirm that the public IP address of your computer is in the IP address whitelist. See Configure an IP address whitelist.

image

I'm getting a login error from the DMS client even though my credentials are correct.

Use the DMS web console instead — this is described in the Connect using DMS section above. If you still encounter errors after switching to the web console, see FAQ about logging on to a database using DMS.

What's next