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.
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 navigate to the DMS logon page.

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
testuserand a user-defined password.Select a Control Mode. In this example, select Flexible Management.
NoteFlexible 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.
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
dbtestdatabase as an example. You can also double-click another database to switch to it.NoteIf 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
button to the right of the instance name to refresh the database list and display the target database.
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.
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.
Open the local Microsoft SQL Server Management Studio 19.0 (SSMS) client.
Select Connect > Database Engine.
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.
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.
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.
Add the Microsoft JDBC driver to your Maven project to access the SQL Server database.
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(); } } } } }Test whether the connection is successful.
Save the above code as a
SqlServerConnection.javafile. 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.




