All Products
Search
Document Center

ApsaraDB RDS:Connect to an RDS for SQL Server instance

Last Updated:Dec 03, 2025

After you complete the initial configuration for an ApsaraDB RDS for SQL Server instance, you can connect to the RDS instance using various methods such as Data Management (DMS) and Microsoft SQL Server Management Studio (SSMS) to perform the required operations. This topic describes how to connect to an RDS instance using these connection methods.

Prerequisites

  • An RDS instance is created. For more information, see Create an ApsaraDB RDS for SQL Server instance.

  • A database is created in the RDS instance, and an account is created for the database. For more information, see Create accounts and databases.

  • An IP address whitelist is configured for the RDS instance. This way, you can connect to the RDS instance from the Elastic Compute Service (ECS) instance on which a client is deployed or from an on-premises device. For more information, see Configure an IP address whitelist.

    Note
    • If you want to connect an ECS instance to the RDS instance over an internal network, make sure that these instances reside in the same virtual private cloud (VPC) in the same region, and the private IP address of the ECS instance is added to an IP address whitelist of the RDS instance.

    • If you want to connect an on-premises device to the RDS instance, make sure that the public IP address of the on-premises device is added to an IP address whitelist of the RDS instance.

Procedure

You can use DMS, a client, or a Java application to connect to the RDS instance.

Method 1: Use DMS to connect to the RDS instance

DMS is a one-stop data management platform that allows you to manage data throughout its lifecycle. You can use DMS to manage global data assets, govern data, design and develop databases, integrate data, develop data, and consume data. These features help enterprises obtain value from data in an efficient and secure manner and facilitate the digital transformation of enterprises. For more information, see What is DMS?

You can use DMS to log on to your RDS instance to manage and use data without the need to configure IP address whitelists or connection types for the RDS instance.

  1. Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.

  2. On the page that appears, click Log On to Database.

    image..png

  3. In the Log on to Database Instance dialog box, enter the logon information and click Login.

    image

    • Configure the Access Mode parameter. In this topic, Account + password login is selected.

    • Configure the Database Account and Database Password parameters. In this topic, a privileged account named testuser and a custom password are used.

    • Configure the Control Mode parameter. In this topic, Flexible Management is selected.

      Note
      • If your RDS instance is managed in Flexible Management mode, you can use DMS to manage the instance free of charge. If your RDS instance is managed in Stable Change or Security Collaboration, fees are generated.

      • Compared with the Flexible Management mode, the Stable Change and Security Collaboration modes provide more features and enhanced database management capabilities. If your RDS instance is for trial use, we recommend that you select Flexible Management.

  4. View the database. In the left-side navigation pane of the DMS console, choose Database Instances > Instances Connected to view the database that you create. In this topic, the database named dbtest is displayed. You can also double-click a database.

image

Note

If the RDS instance exists but the required database is not displayed on the Instance Connected page of the DMS console, troubleshoot the issue based on the following information:

  • The logon account does not have the permissions to connect to the required database. In this case, you can go to the Accounts page of the RDS instance, find the logon account, and then click Change Permissions in the Actions column to grant the required permissions.

  • The metadata of the required database is not synchronized. In this case, move the pointer over the RDS instance to which the required database belongs and click the image icon to the right of the instance name. Then, you can find the required database.

  1. After you use DMS to connect to the RDS instance, perform the required operations on the SQL Console tab based on your business requirements. The operations include creating databases and tables and querying or modifying table data.

Method 2: Use the SSMS client to connect to the RDS instance

Microsoft SQL Server Management Studio (SSMS) client is a GUI tool that enables you to manage and handle SQL Server databases. SSMS can be used to connect to different SQL Server databases such as RDS instances, on-premises SQL Server instances, and instances that run SQL Server in other clouds. For more information, see Download SQL Server Management Studio (SSMS).

This section provides an example on how to use SSMS 19.0 to connect to an RDS instance.

Note
  • We recommend that you download the latest version of SSMS to support all SQL Server versions.

  • If you want to use a client to connect to an RDS instance, you must configure an IP address whitelist for the RDS instance and obtain the endpoint of the RDS instance based on your business requirements.

  1. Start the SSMS 19.0 client.

  2. Choose Connect > Database Engine.

  3. In the Connect to Server dialog box, configure the parameters that are required for the logon.

    Parameter

    Example value

    Description

    Server name

    rm-2ze****.rds.aliyuncs.com,1433

    The endpoint and port number of the RDS instance. Enter the public endpoint and public port number obtained when you apply for the public endpoint. Separate the endpoint and port number with a comma (,).

    Authentication

    SQL Server Authentication

    The authentication mode of SQL Server.

    Username

    testuser

    The username of the account for the RDS instance.

    Password

    Test_pw123

    The password of the account for the RDS instance.

  4. Click Connect.

    After the connection is successful, the connection information is displayed on the left side of SSMS.

Method 3: Use a Java application to connect to an RDS instance

This section describes how to connect a Java application to the RDS instance by using Java Database Connectivity (JDBC).

Note

Before the connection, you must add the IP address of the environment in which the application runs to the IP address whitelist of the RDS instance. For example, you can add the IP address of the ECS instance or on-premises device. For more information, see Configure an IP whitelist.

  1. Add the JDBC driver to the Maven project to connect to the RDS instance.

    Method 1: Add the dependency to the pom.xml file of the Maven project

    Note
    • We recommend that you select the version of the dependency based on the Java version. For example, the mssql-jdbc-12.2.0.jre8.jar file in the 12.2.0 package is used with Java 8 or later.

    • For more information about how to view the historical versions of the dependency, see Official documentation.

    <dependency>
      <groupId>com.microsoft.sqlserver</groupId>
      <artifactId>mssql-jdbc</artifactId>
      <version>12.2.0.jre8</version> <!-- Query the latest version number. -->
    </dependency>

    image

    After the dependency is added, click the image icon. The dependency in the pom.xml file is automatically downloaded.

    image

    Method 2: Manually download the JDBC driver and add the driver to the classpath of the Maven project

    1. Download the JDBC driver that matches your Java version. For more information, see Download Microsoft JDBC Driver for SQL Server.

      The Microsoft JDBC Driver for SQL Server is a Type 4 JDBC driver that provides database connectivity by using the standard JDBC APIs available on the Java platform. The Microsoft JDBC Driver for SQL Server provides access to SQL Server from any Java application, application server, or Java-enabled applet.
    2. Download and decompress the package. Then, save the JAR file, such as sqljdbc4.jar or sqljdbc.jar, to the project.

      In this example, IntelliJ IDEA is used to describe how to save a file to the project.

      image

      image

      image

  2. Compile the sample code to connect to an RDS instance by using Java.

    You must use the actual endpoint, database name, username, password, and SQL statement. For more information, see View and change the endpoints and port numbers.

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.ResultSet;
    
    public class testMSSQLJDBC {
    
        public static void main(String[] args) {
            // Enter the endpoint of the RDS instance. If the application is deployed on an ECS instance, enter the internal endpoint. If the application is deployed on an on-premises device or in other environments, enter the public endpoint.
            String url = "jdbc:sqlserver://rm-2vc367d081200******.mssql.cn-chengdu.rds.aliyuncs.com:1433;"
                    + "database=YourDatabaseName;"
                    + "encrypt=true;"
                    + "trustServerCertificate=true;"
                    + "loginTimeout=30;";
            // Enter the username and password. If you do not use Windows authentication, you must specify the username and password.
            String username = "usernametest";
            String password = "Passwordtest!";
    
            // Create a connection object.
            Connection connection = null;
    
            try {
                // Load the JDBC driver.
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                // Establish a connection to the RDS instance.
                connection = DriverManager.getConnection(url, username, password);
                System.out.println("Connection succeeded!");
    
                // Create a Statement object to execute SQL statements.
                Statement statement = connection.createStatement();
                // Run the SQL query. You must use the actual table name and column name.
                String sql = "SELECT TOP 10 * FROM YourTableName";
                ResultSet resultSet = statement.executeQuery(sql);
    
                // Process the result set.
                while (resultSet.next()) {
                    System.out.println("Column 1: " + resultSet.getString("YourColumnName1"));
                    System.out.println("Column 2: " + resultSet.getString("YourColumnName2"));
                }
    
                // Close the result set.
                resultSet.close();
                // Close the Statement object.
                statement.close();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                // Close the connection.
                if (connection != null) {
                    try {
                        connection.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
  3. Test whether the connection is successful.

    Save the modified code to the SqlServerConnection.java file. Then, compile and run the application in the command line or integrated development environment (IDE). If the configuration is correct, the following result is generated, and the application is connected to the RDS instance.

    image

FAQ

I want to connect to my RDS instance using a public endpoint. However, the public IP address keeps changing. What do I do?

We recommend that you add more CIDR blocks to an IP address whitelist of your RDS instance to meet business requirements. For more information, see Configure an IP address whitelist and How do I obtain the public IP address of an external server or a client that is connected to an ApsaraDB RDS for SQL Server instance?

Important

The 0.0.0.0/0 CIDR block allows access from any IP address to the RDS instance. If you add 0.0.0.0/0 to a whitelist for testing, modify this entry immediately after the test is complete.

How do I use Function Compute to obtain data from my RDS instance?

You can install third-party dependencies on Function Compute. Then, you can obtain data from your RDS instance using the built-in modules that are provided by the third-party dependencies in Function Compute. For more information, see Install third-party dependencies on Function Compute.

I have logged on to the RDS instance using DMS. However, the required database is not displayed in the DMS console. Why?

If the RDS instance exists but the required database is not displayed on the Instance Connected page of the DMS console, troubleshoot the issue based on the following information:

  • The logon account does not have the permissions to connect to the required database. In this case, you can go to the Accounts page of the RDS instance, find the logon account, and then click Change Permissions in the Actions column to grant the required permissions. For more information, see Modify the permissions of an account.

  • The metadata of the required database is not synchronized. In this case, move the pointer over the RDS instance to which the required database belongs and click the image icon to the right of the instance name. Then, you can find the required database.

I cannot use SSMS to connect to my RDS instance from my computer. Why?

If you want to use SSMS to connect to your RDS instance from your computer, make sure that the following operations are complete:

  • Apply for a public endpoint and the use the public endpoint to connect your on-premises device to the RDS instance. You are not charged for the Internet traffic that is generated to apply for the public endpoint and for subsequent usage. For more information, see Apply for or release a public endpoint.

    image

  • Add the IP address of your on-premises device to the IP address whitelist of the RDS instance. For more information, see Configure an IP address whitelist.

    image

I failed to log on to the RDS instance from the DMS client, even though the password and other information are correct. Why?

Log on to the RDS instance from the DMS web console, as described in Method 1. We do not recommend using the DMS client. If a logon error occurs, see FAQ about logging on to a database using DMS.