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 use DMS, a client, or a Java application to connect to the SQL Server database.
Use 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. The built-in Database Backup Service (DBS) also provides low-cost and highly reliable backup and recovery capabilities. DMS is designed to help enterprises efficiently and securely unlock the value of their data and accelerate their digital transformation.
You can use DMS to log on to an RDS for SQL Server instance without configuring an IP address whitelist or selecting a connection type.
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.
Click Log On to Database to open the DMS logon page.

In the Log on to Database Instance dialog box, enter your credentials and click Log In.

Select an Access Mode. This tutorial uses Account + password login as an example.
Enter the Database Account and Database Password. This tutorial uses the privileged account
testuserand a custom password as an example.Select a Control Mode. This tutorial uses Flexible Management as an example.
NoteThe Flexible Management mode is free of charge. The Stable Change and Security Collaboration modes incur fees.
Unlike the Flexible Management Control Mode, the Stable Change and Security Collaboration modes offer more features and greater control over the database. If you are trying out an RDS for SQL Server instance, we recommend that you select the Flexible Management mode.
View the database. After you log on, you can find the new database in the Instances Connected section in the left-side navigation pane of the DMS console. This tutorial uses the
dbtestdatabase as an example. You can also double-click other databases to switch between them.
NoteIf the instance exists but the target database is not displayed in the list of connected instances in DMS, the possible causes are:
The logon account does not have permissions to access the target database: You can go to the Accounts page of the RDS instance, find the target account, and click Change Permissions in the Actions column to grant permissions.
The database tree is not displayed because the metadata is out of sync: Move the pointer over the instance to which the target database belongs and click the
icon next to the instance name to refresh the database list and display the target database.
After you log on to the SQL Server database in DMS, you can create databases, create tables, query data, and modify table data on the SQL Console tab.
Use SSMS
Microsoft SQL Server Management Studio (SSMS) is a graphical user interface (GUI) tool used to manage and administer SQL Server. You can use it to connect to various SQL Server databases, including RDS for SQL Server instances, on-premises SQL Server instances, or SQL Server instances in other clouds.
This tutorial shows how to connect to an RDS for SQL Server instance by using Microsoft SQL Server Management Studio 19.0 (SSMS).
We recommend that you download the latest client version to ensure support for all SQL Server versions.
To connect to an instance by using a client, you must first configure an IP address whitelist and obtain the instance endpoint.
Start Microsoft SQL Server Management Studio 19.0 (SSMS) on your local computer.
Choose Connection > Database Engine.
In the Connect to Server dialog box, enter the credentials.
Parameter
Value
Description
Server name
rm-2ze****.rds.aliyuncs.com,1433
The endpoint and port of the RDS instance. Enter the Public Address and Outside the network port that you obtained. Separate the endpoint and port with a comma (,).
Authentication
SQL Server Authentication
The authentication method for SQL Server.
Username
testuser
The username for the RDS instance account.
Password
Test_pw123
The password for the RDS instance account.
Click Connection.
After a successful connection, the database connection information is displayed in the left-side navigation pane of SSMS.
Use a Java application
This section shows how to connect to an RDS for SQL Server instance from a Java application by using Java Database Connectivity (JDBC).
Before you connect to the database, add the IP address of the environment where the application runs (such as an ECS instance or an on-premises device) to the IP address whitelist of the RDS for SQL Server instance. For more information, see Configure an IP whitelist.
In your Maven project, add the Microsoft JDBC driver for SQL Server.
Write sample code to connect to a SQL Server database by using Java, as shown in the following example:
Replace the endpoint, database name, username, password, and SQL statement in the sample code with actual values. For more information, see View or modify endpoints and ports.
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) { // Specify the database endpoint. Use the internal endpoint if your application is deployed on an ECS instance. Use the public endpoint if it is deployed on-premises 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;"; // If you do not use Windows Authentication, you must specify a 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 SQL Server database. connection = DriverManager.getConnection(url, username, password); System.out.println("Connection successful!"); // Create a Statement object to execute SQL statements. Statement statement = connection.createStatement(); // Execute the SQL query. Replace the table name and column names with your actual information. 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(); } } } } }Test the connection.
Save the code as a
SqlServerConnection.javafile. Compile and run the program from the command line or in an IDE. If the configuration is correct, the program produces output similar to the following, which indicates a successful connection to the SQL Server database.
Troubleshoot connection failures
For more information, see Troubleshoot connection issues.





