重要
Azure Data Studio 将于 2026 年 2 月 28 日停用。 建议使用 Visual Studio Code。 有关迁移到 Visual Studio Code 的详细信息,请访问 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 |
要使用的身份验证模式,接受的值:AzureMFA 、SqlLogin 、Integrated 等。 |
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"}