This tutorial shows you how to use the console to quickly create an ApsaraDB RDS for SQL Server instance, configure a database and account for the instance, and connect to it using various methods.
If you are new to Alibaba Cloud RDS, review the Alibaba Cloud RDS Usage Limits.
Prerequisites
If you use a Resource Access Management (RAM) user to create an RDS instance, the AliyunRDSFullAccess and AliyunBSSOrderAccess policies must be attached to the RAM user. For more information, see Use RAM for resource authorization.
Billing
Creating an RDS SQL Server instance incurs instance type and storage fees. These fees depend on parameters including the billing method, RDS edition, instance type, storage type, and storage capacity.
1. Quickly create an RDS for SQL Server instance
This tutorial shows you how to use the Quick Creation method to create an ApsaraDB RDS for SQL Server instance. Compared with the Standard Creation method, Quick Creation lets you skip non-essential parameters and focus on core ones. You only need to specify key parameters to create an instance. This helps you get started quickly. To configure additional parameters during creation, see Create an ApsaraDB RDS for SQL Server instance.
Go to the ApsaraDB RDS console and click Create Instance.
At the top of the buy page, select Quick Creation.
Select a Billing Method. ApsaraDB RDS for SQL Server offers the following two billing methods:
Billing method
Use cases
Benefits
Subscription
Long-term use of ApsaraDB RDS for SQL Server instances.
The subscription billing method is more cost-effective than the pay-as-you-go billing method. The longer the subscription duration, the higher the discount.
Pay-as-you-go
Short-term use of ApsaraDB RDS for SQL Server instances.
You can release an instance at any time to stop billing.
You can also create a Pay-as-you-go instance, and after you confirm that the instance meets your requirements, change the billing method from pay-as-you-go to subscription.
Select the Region for the instance.
ImportantAfter you purchase an ApsaraDB RDS instance, you cannot change its region. Choose a region carefully.
To connect to the ApsaraDB RDS instance from an ECS instance over an internal network, create them in the same region. Otherwise, the ECS instance can connect to the ApsaraDB RDS instance only over the Internet, which can reduce performance.
To connect from a non-ECS device like an on-premises server or a computer, choose a region close to your device to minimize network latency. You can then connect to the instance by using its public endpoint.
Select an Database Engine. This tutorial uses SQL Server as an example.
Select an Instance Specifications.
ApsaraDB RDS for SQL Server provides a variety of instance specifications. You can select one based on your business requirements. If the selected specification does not meet your needs, you can change the configuration after purchase or select Standard Creation at the top of the page to customize the settings. For more information, see Create an ApsaraDB RDS for SQL Server instance.
-
Select a Storage Capacity.
The storage capacity includes the space for data, system files, log files, and transaction files. The available range of storage capacity depends on the instance type and storage type that you select. You can adjust the storage capacity in 5 GB increments.
NoteThe storage capacity of some instances with local SSDs is coupled with their instance type. This limitation does not apply to ESSDs or SSD cloud disks.
Configure the network and vSwitch. The network type defaults to VPC (Virtual Private Cloud).
ImportantECS and ApsaraDB RDS instances in the same VPC can communicate over an internal network, even if they are in different vSwitches.
You cannot change the VPC after an instance is created. To connect to the ApsaraDB RDS instance from an ECS instance over an internal network, you must place both instances in the same region and VPC.
(Optional) View more settings. In Quick Creation, Alibaba Cloud automatically configures other parameters for you by default. You can click More Configurations (Optional) to view other information.
Select the Quantity of instances. Quick Creation supports purchasing a maximum of 10 instances at a time. Select a quantity based on your actual needs. In this tutorial, 1 is selected by default.
(Optional) If you set the Billing Method to Subscription, you must also specify a Duration.
You can also select Enable Auto-renewal to prevent service interruptions caused by missed renewals.
Click Confirm Order and complete the payment.
To view the instance, go to the Instance List page. In the top navigation bar, select the region where the instance was created. Then, find the instance based on its Creation Time.
NoteInstance creation takes about 1 to 10 minutes. You can view the creation progress on the Task Center page. After the instance is created, refresh the Instance List page.
2. Create a database
Go to the Instances page. In the top navigation bar, select the region where you created the instance in Step 1, and then click the instance ID.
In the left-side navigation pane, click Databases. Then, click Create Database.
In the panel that appears, configure the parameters.
Set Database Name to
dbtestand Supported Character Set to Chinese_PRC_CI_AS. Then, click Create.You can view the new database on the Databases page or after you connect to the SQL Server instance.
The dbtest database has a status of Running and uses the Chinese_PRC_CI_AS character set.
3. Create an account
On the instance details page, in the navigation pane on the left, click Accounts.
Click Account Password Policy to configure a password expiration policy.
NoteShared and serverless instances do not support setting a custom password policy. For these instance types, you can skip this step.
Click Create Account and configure the parameters in the panel that appears.
NoteAn error might occur if you use a duplicate account name or attempt to create accounts too frequently, for example, before the previous creation process is complete. If this happens, check if the account name is already in use, or wait for the previous creation process to finish before you try again.
Set the Database Account. For this tutorial, the Database Account is set to
testuser.Select an Account Type. RDS for SQL Server allows you to create a Privileged Account, a Standard Account, and a System Admin Account. This tutorial creates a Privileged Account. For more information, see Methods for creating other account types.
ImportantThe first account for an RDS for SQL Server instance must be a privileged account, and each instance can have only one privileged account. This account has read and write permissions on all databases in the instance. Account creation will fail if a privileged account already exists on your instance.
Enter a password in the New Password field and confirm it in the Confirm Password field.
Apply the password policy from step 2 to this privileged account.
Click OK to create the account.
Refresh the Accounts page to view the new privileged account.
The testuser account is a privileged account and is now active.
4. Configure secure access
If you plan to connect to the database using a command-line interface (CLI) or a client, first add the IP address of your ECS instance or on-premises device to an IP address whitelist for the RDS SQL Server instance. Then, obtain the appropriate internal or public endpoint based on your access type to connect to the instance. If you plan to connect using Alibaba Cloud Data Management (DMS), you can skip to Step 5.
4.1 Configure an IP whitelist
On the instance details page, in the left-side navigation pane, click Whitelist and SecGroup.
Click Create Whitelist, enter a Whitelist Name, and add the IP address of the application server to the IP address whitelist.
Click OK.
Refresh the Whitelist and SecGroup page to view the IP address whitelist that you added.
The IP address whitelist group db_whitelist is successfully added and contains the IP addresses that you configured.
4.2 Select a connection type
You can connect to an instance over an internal network or the public internet. If your setup meets the conditions for internal network access, use the instance's internal endpoint to connect. If the conditions are not met, or if you connect from an on-premises device, you must use the public endpoint. The conditions for internal network access and the methods for obtaining the endpoints are described below.
To connect to the instance over an internal network, your setup must meet the following conditions:
The connecting ECS instance must be in the same region and use the same network type as the RDS instance.
If both the ECS instance and the RDS instance use the virtual private cloud (VPC) network type, they must also be in the same VPC.
Scenario | Endpoint | Method |
For internal network access. | Internal endpoint | On the instance details page, click Database Connection in the left navigation pane to view the instance endpoint and port number. The page shows connection information, including the internal endpoint and internal port (1433 by default) of the instance. Note The public endpoint appears only after you click Apply for Public Endpoint. |
Connecting from an ECS instance without internal network access. | Public endpoint | |
Connecting from an on-premises device. |
5. Connect to an ApsaraDB SQL Server instance
You can connect to a SQL Server database by using Alibaba Cloud Data Management Service (DMS), a client, or a Java application.
Method 1: Use DMS
Data Management Service (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) in DMS also provides low-cost, highly reliable backup and recovery. DMS helps enterprises efficiently and securely unlock the value of their data and accelerates their digital transformation.
You can use DMS to quickly and easily log on to an ApsaraDB for SQL Server instance to manage and use data. This method eliminates the need to configure an IP address whitelist or select a connection type for the 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.
Click Log On to Database to open the DMS logon page.
In the Log on to Database Instance dialog box, enter the logon information 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.Select a Control Mode. This tutorial uses Flexible Management as an example.
NoteFlexible Management is free of charge. Stable Change and Security Collaboration incur fees.
Compared to the Flexible Management control mode, Stable Change and Security Collaboration offer more advanced database management features. If you are trying out ApsaraDB for SQL Server, we recommend selecting the Flexible Management mode.
After you log on, the newly created database appears under Instances Connected in the left navigation pane 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 list of connected instances in DMS, the cause may be one of the following:
The logon account does not have permissions to access the target database: Go to the Accounts page of the ApsaraDB RDS instance, find the target account, and click Change Permissions in the Actions column to grant the required permissions.
The directory is not displayed because the metadata is not synchronized: Hover the pointer over the instance that contains the target database and click the
icon to the right of the instance name. This refreshes the list to display the target database.
After logging on to the database in DMS, use the SQL Console tab to create databases and tables, and to query and modify data.
Method 2: Use SSMS
Microsoft SQL Server Management Studio (SSMS) is a graphical user interface (GUI) tool for managing and administering SQL Server. You can use it to connect to different SQL Server databases, such as ApsaraDB for SQL Server instances, on-premises SQL Server instances, or SQL Server instances hosted on other clouds.
This tutorial demonstrates how to connect to an ApsaraDB for SQL Server instance by using Microsoft SQL Server Management Studio 19.0 (SSMS).
We recommend that you download the latest version of SSMS to ensure compatibility with all SQL Server versions.
To connect by using a client, you must first configure an IP address whitelist and obtain the instance endpoint.
Open your local Microsoft SQL Server Management Studio (SSMS) 19.0 client.
Select Connection > Database Engine.
In the Connect to Server dialog box, enter the logon information.
Parameter
Value
Description
Server name
rm-2ze****.rds.aliyuncs.com,1433
The endpoint and port number of the ApsaraDB RDS instance. Enter the Public Address and Outside the network port that you obtained when you applied for a public endpoint. Separate the endpoint and port number with a comma (,).
Authentication
SQL Server Authentication
The authentication method for SQL Server.
Username
testuser
The username for the ApsaraDB RDS instance account.
Password
Test_pw123
The password for the ApsaraDB RDS instance account.
Click Connection.
After a successful connection, SSMS displays the connection information on the left.
Method 3: Use a Java application
This section describes how to use JDBC to connect to an ApsaraDB for SQL Server instance from a Java application.
Before you connect, add the IP address of the environment where the application runs, such as the IP address of an ECS instance or an on-premises device, to the IP address whitelist of the ApsaraDB for SQL Server instance. For more information, see Configure an IP address whitelist.
Add the Microsoft JDBC driver to your Maven project to access a SQL Server database.
Write sample code to connect to a SQL Server database from Java:
Replace the endpoint, database name, username, password, and SQL statement in the sample code with your actual values. For more information, see View or modify an 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 your application runs on an ECS instance, or the public endpoint if it runs on-premises or in other environments. String url = "jdbc:sqlserver://rm-2vc367d081200******.mssql.cn-chengdu.rds.aliyuncs.com:1433;" + "database=YourDatabaseName;" + "encrypt=true;" + "trustServerCertificate=true;" + "loginTimeout=30;"; // Specify the username and password 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"); // Connect to the SQL Server database. connection = DriverManager.getConnection(url, username, password); System.out.println("Connection succeeded!"); // Create a Statement object to run SQL statements. Statement statement = connection.createStatement(); // Run a SQL query. Replace the table 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 the connection.
Save the code as a
SqlServerConnection.javafile, and compile and run it from the command line or in an IDE. If the configuration is correct, the program prints the following output, which indicates a successful connection to the SQL Server database.Connection succeeded!
