快速入門:設定 Azure VM 以連線到 Azure SQL Database 受控執行個體Quickstart: Configure Azure VM to connect to an Azure SQL Database Managed Instance

此快速入門示範了如何設定 Azure 虛擬機器,以使用 SQL Server Management Studio (SSMS) 連線到 Azure SQL Database 受控執行個體。This quickstart shows you how to configure an Azure virtual machine to connect to an Azure SQL Database Managed Instance using SQL Server Management Studio (SSMS). 如需如何使用點對站連線從內部部署用戶端電腦進行連線的快速入門,請參閱設定點對站連線For a quickstart showing how to connect from an on-premises client computer using a point-to-site connection, see Configure a point-to-site connection

先決條件Prerequisites

此快速入門會使用在建立受控執行個體中建立的資源作為起點。This quickstart uses the resources created in Create a Managed Instance as its starting point.

登入 Azure 入口網站Sign in to the Azure portal

登入 Azure 入口網站Sign in to the Azure portal.

在受控執行個體 VNet 中建立新的子網路Create a new subnet in the Managed Instance VNet

下列步驟可在受控執行個體 VNet 中建立新的子網路,以便 Azure 虛擬機器可以連線到受控執行個體。The following steps create a new subnet in the Managed Instance VNet so an Azure virtual machine can connect to the Managed Instance. 受控執行個體子網路專門用於受控執行個體。The Managed Instance subnet is dedicated to Managed Instances. 您無法在該子網路中建立 Azure 虛擬機器等其他資源。You can't create any other resources, like Azure virtual machines, in that subnet.

  1. 您在建立受控執行個體快速入門中建立過受控執行個體的資源群組,請開啟該資源群組。Open the resource group for the Managed Instance that you created in the Create a Managed Instance quickstart. 選取受控執行個體的虛擬網路。Select the virtual network for your Managed Instance.

    受控執行個體資源

  2. 選取 [子網路],然後選取 [+ 子網路] 來建立新的子網路。Select Subnets and then select + Subnet to create a new subnet.

    受控執行個體子網路

  3. 使用此資料表中的資訊填妥表單:Fill out the form using the information in this table:

    設定Setting 建議值Suggested value 說明Description
    名稱Name 任何有效名稱Any valid name 如需有效的名稱,請參閱命名規則和限制For valid names, see Naming rules and restrictions.
    位址範圍 (CIDR 區塊)Address range (CIDR block) 有效範圍A valid range 針對此快速入門,使用預設值即可。The default value is good for this quickstart.
    網路安全性群組Network security group NoneNone 針對此快速入門,使用預設值即可。The default value is good for this quickstart.
    路由表Route table NoneNone 針對此快速入門,使用預設值即可。The default value is good for this quickstart.
    服務端點Service endpoints 已選取 00 selected 針對此快速入門,使用預設值即可。The default value is good for this quickstart.
    子網路委派Subnet delegation NoneNone 針對此快速入門,使用預設值即可。The default value is good for this quickstart.

    為用戶端 VM 新增受控執行個體子網路

  4. 選取 [確定] 以在受控執行個體 VNet 中建立這個額外的子網路。Select OK to create this additional subnet in the Managed Instance VNet.

在 VNet 的新子網路中建立虛擬機器Create a virtual machine in the new subnet in the VNet

下列步驟顯示如何在建立受控執行個體的相同 VNet 中建立虛擬機器。The following steps show you how to create a virtual machine in the new subnet to connect to the Managed Instance.

準備 Azure 虛擬機器Prepare the Azure virtual machine

由於 SQL 受控執行個體是放置在您的私人虛擬網路中,因此您必須使用已安裝的 SQL 用戶端工具 (例如 SQL Server Management Studio 或 Azure Data Studio) 建立 Azure VM。Since SQL Managed Instance is placed in your private Virtual Network, you need to create an Azure VM with an installed SQL client tool, like SQL Server Management Studio or Azure Data Studio. 此工具可讓您連線到受控執行個體,並執行查詢。This tool lets you connect to the Managed Instance and execute queries. 此快速入門使用 SQL Server Management Studio。This quickstart uses SQL Server Management Studio.

要使用所有的必要工具建立用戶端虛擬機器,最簡單的方式是使用 Azure Resource Manager 範本。The easiest way to create a client virtual machine with all necessary tools is to use the Azure Resource Manager templates.

  1. 請務必在另一個瀏覽器分頁中登入 Azure 入口網站。接著請選取下列按鈕以建立用戶端虛擬機器,並安裝 SQL Server Management Studio:Make sure that you're signed in to the Azure portal in another browser tab. Then, select the following button to create a client virtual machine and install SQL Server Management Studio:

  2. 使用下表中的資訊填妥表單:Fill out the form using the information in the following table:

    設定Setting 建議值Suggested value 說明Description
    訂用帳戶Subscription 有效的訂用帳戶A valid subscription 必須是您有權限在其中建立新資源的訂用帳戶。Must be a subscription in which you have permission to create new resources.
    資源群組Resource Group 您在建立受控執行個體快速入門中指定的資源群組。The resource group that you specified in the Create Managed Instance quickstart. 此資源群組必須是 VNet 所在的資源群組。This resource group must be the one in which the VNet exists.
    LocationLocation 資源群組的位置The location for the resource group 根據選取的資源群組填入此值。This value is populated based on the resource group selected.
    虛擬機器名稱Virtual machine name 任何有效名稱Any valid name 如需有效的名稱,請參閱命名規則和限制For valid names, see Naming rules and restrictions.
    系統管理員使用者名稱Admin Username 任何有效的使用者名稱Any valid username 如需有效的名稱,請參閱命名規則和限制For valid names, see Naming rules and restrictions. 請勿使用 "serveradmin",因為這是保留的伺服器層級角色。Don't use "serveradmin" as that is a reserved server-level role.
    您隨時要連線至 VM 時,都可以使用這個使用者名稱。You use this username any time you connect to the VM.
    密碼Password 任何有效密碼Any valid password 密碼長度至少必須有 12 個字元,而且符合定義的複雜度需求The password must be at least 12 characters long and meet the defined complexity requirements.
    您隨時要連線至 VM 時,都可以使用這個密碼。You use this password any time you connect to the VM.
    虛擬機器大小Virtual Machine Size 任何有效大小Any valid size 在此快速入門中,使用此範本的預設值 Standard_B2s 就已足夠。The default in this template of Standard_B2s is sufficient for this quickstart.
    LocationLocation [resourceGroup().location]。[resourceGroup().location]. 請勿變更此值。Don't change this value.
    虛擬網路名稱Virtual Network Name 您在其中建立受控執行個體的虛擬網路。The virtual network in which you created the Managed Instance.
    子網路名稱Subnet name 您在上一個程序中建立的子網路名稱The name of the subnet that you created in the previous procedure 請勿選擇您在其中建立受控執行個體的子網路。Don't choose the subnet in which you created the Managed Instance.
    構件位置artifacts Location [deployment().properties.templateLink.uri][deployment().properties.templateLink.uri] 請勿變更此值。Don't change this value.
    構件位置 SAS 權杖artifacts Location Sas token 保留空白leave blank 請勿變更此值。Don't change this value.

    建立用戶端 VM

    如果您使用建立受控執行個體中建議的 VNet 名稱與預設子網路,則不需要變更最後兩個參數。If you used the suggested VNet name and the default subnet in creating your Managed Instance, you don't need to change last two parameters. 否則,您應該將這些值變更為您在設定網路環境時輸入的值。Otherwise you should change these values to the values that you entered when you set up the network environment.

  3. 選取 [我同意上方所述的條款及條件] 核取方塊。Select the I agree to the terms and conditions stated above checkbox.

  4. 選取 [購買] 以在您的網路中部署 Azure VM。Select Purchase to deploy the Azure VM in your network.

  5. 選取 [通知] 圖示以檢視部署的狀態。Select the Notifications icon to view the status of deployment.

重要

在虛擬機器建立大約 15 分鐘之前請不要繼續,讓建立後指令碼有時間可以安裝 SQL Server Management Studio。Do not continue until approximately 15 minutes after the virtual machine is created to give time for the post-creation scripts to install SQL Server Management Studio.

連線至虛擬機器Connect to virtual machine

下列步驟顯示如何使用遠端桌面連線來連線到新建立的虛擬機器。The following steps show you how to connect to your newly created virtual machine using a remote desktop connection.

  1. 部署完成之後,請移至虛擬機器資源。After deployment completes, go to the virtual machine resource.

    VM

  2. 選取 [ 連接]。Select Connect.

    將顯示遠端桌面通訊協定檔案 (.rdp 檔案) 表單,其中包含虛擬機器的公用 IP 位址與連接埠號碼。A Remote Desktop Protocol file (.rdp file) form appears with the public IP address and port number for the virtual machine.

    RDP 表單

  3. 選取 [下載 RDP 檔案]。Select Download RDP File.

    注意

    您也可以使用 SSH 來連線到您的 VM。You can also use SSH to connect to your VM.

  4. 關閉連線至虛擬機器表單。Close the Connect to virtual machine form.

  5. 若要連線至您的 VM,請開啟下載的 RDP 檔案。To connect to your VM, open the downloaded RDP file.

  6. 出現提示時,請選取 [連接]。When prompted, select Connect. 在 Mac 上,您需要 RDP 用戶端,例如來自 Mac App Store 的遠端桌面用戶端On a Mac, you need an RDP client such as this Remote Desktop Client from the Mac App Store.

  7. 輸入在建立虛擬機器時指定的使用者名稱和密碼,然後選擇 [確定]。Enter the username and password you specified when creating the virtual machine, then choose OK.

  8. 您可能會在登入過程中收到憑證警告。You might receive a certificate warning during the sign-in process. 選擇 [是] 或 [繼續] 以繼續進行連線。Choose Yes or Continue to proceed with the connection.

您已連線到 [伺服器管理員] 儀表板中的虛擬機器。You're connected to your virtual machine in the Server Manager dashboard.

使用 SSMS 連線到受控執行個體Use SSMS to connect to the Managed Instance

  1. 在虛擬機器中,開啟 SQL Server Management Studio (SSMS)。In the virtual machine, open SQL Server Management Studio (SSMS).

    由於這是第一次啟動 SSMS,因此需要一些時間才能完成其設定。It takes a few moments to open as it needs to complete its configuration since this is the first time SSMS has been started.

  2. 在 [連接到伺服器] 對話方塊方塊中,於 [伺服器名稱] 方塊中輸入受控執行個體的完整 [主機名稱]。In the Connect to Server dialog box, enter the fully qualified host name for your Managed Instance in the Server name box. 選取 [SQL Server 驗證],提供您的使用者名稱和密碼,然後選取 [連線]。Select SQL Server Authentication, provide your username and password, and then select Connect.

    SSMS 連線

連線之後,您可以檢視 [資料庫] 節點中的系統和使用者資料庫,以及 [安全性]、[伺服器物件]、[複寫]、[管理]、[SQL Server 代理程式] 和 [XEvent Profiler] 節點中的各種物件。After you connect, you can view your system and user databases in the Databases node, and various objects in the Security, Server Objects, Replication, Management, SQL Server Agent, and XEvent Profiler nodes.

後續步驟Next steps