Azure Data Studio 命令行接口

重要

Azure Data Studio 将于 2026 年 2 月 28 日停用。 建议使用 Visual Studio Code。 有关迁移到 Visual Studio Code 的详细信息,请访问 Azure Data Studio 发生了什么情况?

Azure Data Studio 包含一个内置命令行接口,用于控制应用程序的启动方式。 可以通过命令行选项(开关)打开文件、安装扩展、更改显示语言和输出诊断。

Azure Data Studio 中命令行输出的屏幕截图。

有关如何在 Azure Data Studio 中运行命令行工具的示例,请参阅集成终端

注意

虽然 Microsoft Entra ID 是 Azure Active Directory (Azure AD) 的新名称,但为了防止中断现有环境,Azure AD 仍保留在一些硬编码的元素中,例如 UI 字段、连接提供程序、错误代码和 cmdlet。 在本文中,这两个名称可以互换。

命令行帮助

要查看 Azure Data Studio 命令行接口的概述,请在 Azure Data Studio(查看 > 终端)中打开终端或命令提示符并键入 azuredatastudio --help。 输出包含命令行选项的版本、用法示例和列表,如截断示例所示:

Azure Data Studio 1.48.1

Usage: azuredatastudio.exe [options][paths...]

To read output from another program, append '-' (e.g. 'echo Hello World | azuredatastudio.exe -')

Options

  <vscode options>

  -h --help                                  Print usage.
  --aad                                      Use Azure Active Directory authentication, this option is
                                             deprecated - use 'authenticationType' instead.
  -A --applicationName                       Supports providing applicationName
                                             that will be used for connection profile app name.
  -T --authenticationType                    Provide authentication mode to be
                                             used. Accepted values: AzureMFA, SqlLogin, Integrated, etc.
  -c --command <command-name>                Name of command to run, accepted
                                             values: connect, openConnectionDialog
  -Z --connectionProperties                  Supports providing advanced connection properties that
                                             providers support. Value must be a json object containing
                                             key-value pairs in format: '{"key1":"value1"}'
  -D --database <database>                   Name of database
  -E --integrated                            Use Integrated authentication,
                                             this option is deprecated - use 'authenticationType' instead.
  -P --provider                              Connection provider to use, e.g. MSSQL, PGSQL, etc.
  -S --server <server>                       Name of target server or host name.
  --showDashboard                            Whether or not to show dashboard on connection, false by default.
  -U --user <user-name>                      User name/email address

从命令行启动

可以从命令行启动 Azure Data Studio,以快速打开文件、文件夹或项目。 通常在文件夹的上下文中打开 Azure Data Studio。 从打开的终端或命令提示符,导航到机器人的项目文件夹并键入 azuredatastudio

使用查询编辑器启动

有时,在打开 Azure Data Studio 时,可能希望在查询编辑器中打开脚本。 可以通过提供文件的路径,使用现有脚本启动 Azure Data Studio:

azuredatastudio .\samplescript.sql

使用 URI 启动

可以使用 URL 格式从浏览器启动 Azure Data Studio,以便在启动时快速建立连接或打开连接对话框,可以选择在查询编辑器中打开脚本。 支持使用 URI 启动的格式为:

azuredatastudio://{command}?{option1}={value1}&{option2}={value2}...

支持的命令

从命令行启动 Azure Data Studio 时,支持以下命令:

  • connect:使用提供的选项连接到目标服务器
  • openConnectionDialog:使用提供的选项打开连接对话框

支持的选项

URL 可提供以下选项。

选项 说明
provider 要使用的连接提供程序,例如 MSSQL、PGSQL 等。
server 目标服务器名称或主机名。
database 数据库的名称。
user 用户名,
authenticationType 要使用的身份验证模式,接受的值:AzureMFASqlLoginIntegrated 等。
applicationName 提供连接配置文件中使用的应用程序名称。
connectionProperties 提供程序支持的高级连接属性。 值必须是 json 对象,包含键值对,格式为:{"key1":"value1"}

示例

命令提示符:集成身份验证

azuredatastudio --server localhost --authenticationType Integrated

系统可能会提示出现“信任服务器证书”警告。

注意

对于连接到虚拟机中的本地 SQL Server 或 SQL Server 的用户,必须将数据库引擎配置为支持加密连接。 有关完整说明,请参阅将 SQL Server 数据库引擎配置为使用加密连接

命令提示符:使用保存的脚本启动 Azure Data Studio

azuredatastudio --server localhost --provider mssql --user sa .\samplescript.sql

浏览器

azuredatastudio://connect?server=*****&user=*****&authenticationType=*****&connectionProperties={"key1":"value1"}

后续步骤