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.
NoteIf 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.
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.
On the page that appears, click Log On to Database.

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

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
testuserand a custom password are used.Configure the Control Mode parameter. In this topic, Flexible Management is selected.
NoteIf 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.
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
dbtestis displayed. You can also double-click a database.

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
icon to the right of the instance name. Then, you can find the required database.
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.
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.
Start the SSMS 19.0 client.
Choose Connect > Database Engine.
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.
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).
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.
Add the JDBC driver to the Maven project to connect to the RDS instance.
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(); } } } } }Test whether the connection is successful.
Save the modified code to the
SqlServerConnection.javafile. 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.






