All Products
Search
Document Center

ApsaraDB RDS:Connect to an SQL Server instance

Last Updated:Oct 14, 2026

After the initial configuration, you can connect to your SQL Server instance by using methods such as Data Management (DMS) or SQL Server Management Studio (SSMS). This topic describes the steps for each method.

Prerequisites

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

  • You have created a database and an account. For more information, see Create a database and an account.

  • You have configured an IP address whitelist to allow your client, such as an Elastic Compute Service (ECS) instance or an on-premises device, to access the ApsaraDB RDS for SQL Server instance. For more information, see Configure an IP address whitelist.

    Note
    • If you use an Elastic Compute Service (ECS) instance to connect to an ApsaraDB RDS for SQL Server instance over an internal network, the ECS instance and the RDS instance must be in the same region and the same virtual private cloud (VPC). Add the private IP address of the ECS instance to the IP address whitelist.

    • If you use an on-premises device to connect to an ApsaraDB RDS for SQL Server instance, you must add the public IP address of the device to the IP address whitelist.

Procedure

You can log on to the SQL Server database directly using Alibaba Cloud DMS, connect remotely using a client, or connect using a Java application.

Method 1: Log on to the instance using DMS

Data Management (DMS) is a one-stop data management platform that supports the entire data lifecycle. It provides features such as global data asset management, data governance, database design and development, data integration, data development, and data consumption. to help enterprises efficiently and securely extract data value and accelerate their digital transformation.

You can use DMS to quickly and conveniently log on to an ApsaraDB RDS for SQL Server instance for data management and use without needing to configure the instance's IP whitelist or select a connection type.

  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. Click Log On to Database to navigate to the DMS logon page.

    image..png

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

    • For Access Mode, select Account and Password Logon as an example.

    • Enter the Database Account and Database Password. For this tutorial, use the privileged account testuser and a user-defined password.

    • Select a Control Mode. In this example, select Flexible Management.

      Note
      • Flexible Management is free of charge. Stable Change and Security Collaboration incur fees.

      • Compared to the control mode of Flexible Management, Stable Change and Security Collaboration offer more features and enhanced database control. If you are evaluating ApsaraDB RDS for SQL Server, we recommend using the Flexible Management mode.

  4. After a successful logon, you can view the newly created database in the Logged-in Instances list on the left side of the DMS page. This tutorial uses the dbtest database as an example. You can also double-click another database to switch to it.

    Note

    If the instance exists but the target database is not found in the DMS logged-in instance list, it may be for one of the following reasons:

    • The logon account does not have permission to access the target database: Go to the Accounts page on the RDS instance details page and click Actions in the Change Permissions column for the target account to grant permissions.

    • The directory cannot be displayed because metadata is not synchronized: Hover the pointer over the instance to which the target database belongs. Click the image button to the right of the instance name to refresh the database list and display the target database.

  5. After you successfully log on to the SQL Server database in DMS, you can create databases, create tables, and query and change table data in the SQL Console.

Method 2: Connect to the instance using the SSMS client

Microsoft SQL Server Management Studio (SSMS) is a graphical interface tool for managing and working with SQL Server. It can be used to connect to different SQL Server databases, including ApsaraDB RDS for SQL Server instances, on-premises SQL Server instances, or SQL Server instances in the cloud.

This tutorial uses Microsoft SQL Server Management Studio 19.0 (SSMS) as an example to show you how to connect to an ApsaraDB RDS for SQL Server instance using a client.

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

  • Connecting to an instance using a client requires you to preset an IP whitelist and obtain the instance's connection address as needed.

  1. Open the local Microsoft SQL Server Management Studio 19.0 (SSMS) client.

  2. Select Connect > Database Engine.

  3. Enter the logon information in the Connect to Server dialog box.

    Parameter

    Value in this tutorial

    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 obtained when you enabled the public endpoint. Separate the endpoint and port number with a comma (,).

    Authentication

    SQL Server Authentication

    The authentication method for SQL Server.

    Login Name

    testuser

    Enter the account name of the RDS instance.

    Password

    Test_pw123

    Enter the password for the RDS instance account.

  4. To connect to the instance, click Connect.

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

Method 3: Connect to the instance using a Java application

The following section describes how to connect to an ApsaraDB RDS for SQL Server instance using a Java application with JDBC.

Note

Before you connect to the database, add the IP address of the application's runtime environment, such as an ECS instance or an on-premises device, to the IP whitelist of the ApsaraDB RDS for SQL Server instance. For more information, see Set a whitelist.

  1. Add the Microsoft JDBC driver to your Maven project to access the SQL Server database.

    Method 1: Manually add the dependency to the pom.xml file of your Maven project

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

    • To view the history of dependency versions, see the official tutorial.

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

    image

    After you add the dependency, click image. The dependency in the pom.xml file is automatically downloaded.

    image

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

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

      The Microsoft JDBC Driver for SQL Server is a Type 4 JDBC driver that provides database connectivity through the standard JDBC application programming interfaces (APIs) available on the Java platform. It can access SQL Server from any Java application, application server, or Java-enabled applet.
    2. After you download and decompress the file, manually save the JAR file, such as sqljdbc4.jar or sqljdbc.jar, to your project.

      This tutorial uses IntelliJ IDEA as an example to demonstrate the method:

      image

      image

      image

  2. Write the sample code to connect to the SQL Server database using Java, as follows:

    Replace the endpoint, database name, username, password, and SQL command in the example with your actual information. For more information, see View or change the endpoint and port number.

    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 database endpoint. Use the internal endpoint if the application is deployed on an ECS instance. Use the public endpoint if it is deployed locally or in another environment.
            String url = "jdbc:sqlserver://rm-2vc367d081200******.mssql.cn-chengdu.rds.aliyuncs.com:1433;"
                    + "database=YourDatabaseName;"
                    + "encrypt=true;"
                    + "trustServerCertificate=true;"
                    + "loginTimeout=30;";
            // The username and password. You must specify them if you do not use Windows Authentication.
            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 SQL Server database.
                connection = DriverManager.getConnection(url, username, password);
                System.out.println("Connection successful!");
    
                // Create a Statement object to execute SQL commands.
                Statement statement = connection.createStatement();
                // Execute an SQL query. Replace the table name and column names as needed.
                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 above code as a SqlServerConnection.java file. Compile and run the program in the command line or an IDE. If the configuration is correct, the program outputs a result similar to the following, which indicates that the program has successfully connected to the SQL Server database.

    image

FAQ

I want to connect to an RDS instance by using a public endpoint, but my public IP address is unstable and keeps changing. What do you suggest?

We recommend that you add a larger CIDR block to the IP address whitelist to meet your business requirements. For more information, see Configure an IP address whitelist and How do I determine the public IP address of an external server or client for SQL Server?.

Important

0.0.0.0/0 indicates that any IP address can access the RDS instance. If you add 0.0.0.0/0 to the IP address whitelist for testing, modify this entry immediately after the test is complete.

I use Function Compute and want to retrieve data from RDS. How can I do this?

You can install third-party dependencies for your function and use built-in modules to retrieve data from RDS. For more information, see Install third-party dependencies for a function.

I logged on to an RDS instance in DMS, but DMS indicates that no database is found. Why?

If the target database is not in the Instances Connected list, check for the following issues:

  • The logon account does not have permissions to access the target database: Go to the Accounts page of the RDS instance details page. Find the target account and click Change Permissions in the Actions column to grant permissions. For more information, see Modify the permissions of an account.

  • The directory is not displayed because metadata is not synchronized: Hover the pointer over the instance to which the target database belongs and click the image icon to the right of the instance name. This refreshes the database list and displays the target database.

I cannot connect to my RDS instance from my on-premises computer by using SSMS. Why?

To connect to an ApsaraDB RDS for SQL Server instance from an on-premises SSMS client, make sure that the following requirements are met:

  • To access the RDS instance from an on-premises device, you must apply for a public endpoint and use it to connect to the instance. You are not charged for applying for a public endpoint or for the subsequent public traffic that is generated. For more information, see Apply for a public endpoint.

    In the left-side navigation pane of the instance details page, click Database Connection to view the instance's internal endpoint, public endpoint, and port number (1433 by default). A public endpoint looks similar to rm-<instance_id>.mssql.<region>.rds.aliyuncs.com. Before connecting, click Set Whitelist next to the public endpoint to add the IP address of your application server or on-premises device to an IP address whitelist. When you use SQL Server Management Studio to connect, enter the server name in the <public_endpoint>,1433 format.

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

    To do this, go to the instance management page and click Whitelist and Security Group in the left-side navigation pane. On the Whitelist Settings tab, click Add Whitelist Group.

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

We recommend that you log on to the RDS instance from the DMS web console as described in Method 1, instead of using the DMS client. If a logon error occurs, see FAQ about logging on to a database by using DMS for solutions.