You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For more information on the difference between **sqlcmd** versions, see [sqlcmd utility](sqlcmd-utility.md#find-out-which-version-you-have-installed).
20
22
23
+
## [sqlcmd (Go)](#tab/go)
24
+
25
+
**sqlcmd** (Go) supports more Microsoft Entra authentication models, based on the [azidentity package](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). The implementation relies on a Microsoft Entra connector in the [go-sqlcmd driver](https://github.com/microsoft/go-mssqldb).
26
+
27
+
### Command line arguments
28
+
29
+
To use Microsoft Entra authentication, you can use one of two command line switches.
30
+
31
+
`-G` is (mostly) compatible with its usage in **sqlcmd** (ODBC). If a username and password are provided, it authenticates using Microsoft Entra password authentication. If a user name is provided, it uses Microsoft Entra interactive authentication, which may display a web browser. If no username or password is provided, it uses a `DefaultAzureCredential`, which attempts to authenticate through various mechanisms.
32
+
33
+
`--authentication-method=` can be used to specify one of the following authentication types.
34
+
35
+
#### ActiveDirectoryDefault
36
+
37
+
- For an overview of the types of authentication this mode uses, see [Default Azure Credential](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/azidentity#defaultazurecredential).
38
+
- Choose this method if your database automation scripts are intended to run in both local development environments and in a production deployment in Azure. In your development environment, you can use a client secret or an Azure CLI login. Without changing the script from the development environment, you can use a managed identity or client secret on your production deployment.
39
+
- Setting environment variables `AZURE_TENANT_ID` and `AZURE_CLIENT_ID` are necessary for `DefaultAzureCredential` to begin checking the environment configuration and look for one of the following additional environment variables in order to authenticate:
40
+
- Setting environment variable `AZURE_CLIENT_SECRET` configures the `DefaultAzureCredential` to choose `ClientSecretCredential`.
41
+
- Setting environment variable `AZURE_CLIENT_CERTIFICATE_PATH` configures the `DefaultAzureCredential` to choose `ClientCertificateCredential` if `AZURE_CLIENT_SECRET` isn't set.
42
+
- Setting environment variable AZURE_USERNAME configures the `DefaultAzureCredential` to choose `UsernamePasswordCredential` if `AZURE_CLIENT_SECRET` and `AZURE_CLIENT_CERTIFICATE_PATH` aren't set.
43
+
44
+
#### ActiveDirectoryIntegrated
45
+
46
+
This method is currently not implemented, and falls back to `ActiveDirectoryDefault`.
47
+
48
+
#### ActiveDirectoryPassword
49
+
50
+
- This method authenticates using a username and password. It doesn't work if MFA is required.
51
+
52
+
- You provide the user name and password using the usual command line switches or `SQLCMD` environment variables.
53
+
54
+
- Set `AZURE_TENANT_ID` environment variable to the tenant ID of the server if not using the default tenant of the user.
55
+
56
+
#### ActiveDirectoryInteractive
57
+
58
+
This method launches a web browser to authenticate the user.
59
+
60
+
#### ActiveDirectoryManagedIdentity
61
+
62
+
Use this method when running **sqlcmd** (Go) on an Azure VM that has either a system-assigned or user-assigned managed identity. If using a user-assigned managed identity, set the user name to the ID of the managed identity. If using a system-assigned identity, leave user name empty.
63
+
64
+
#### ActiveDirectoryServicePrincipal
65
+
66
+
This method authenticates the provided user name as a service principal ID and the password as the client secret for the service principal. Provide a user name in the form `<service principal id>@<tenant id>`. Set `SQLCMDPASSWORD` variable to the client secret. If using a certificate instead of a client secret, set `AZURE_CLIENT_CERTIFICATE_PATH` environment variable to the path of the certificate file.
67
+
68
+
### Environment variables for Microsoft Entra authentication
69
+
70
+
Some Microsoft Entra authentication settings don't have command line inputs, and some environment variables are consumed directly by the `azidentity` package used by **sqlcmd** (Go).
71
+
72
+
These environment variables can be set to configure some aspects of Microsoft Entra authentication and to bypass default behaviors. In addition to the variables listed previously, the following are specific to **sqlcmd** (Go), and apply to multiple methods.
73
+
74
+
#### SQLCMDCLIENTID
75
+
76
+
Set this environment variable to the identifier of an application registered in Microsoft Entra, which is authorized to authenticate to Azure SQL Database. Applies to `ActiveDirectoryInteractive` and `ActiveDirectoryPassword` methods.
77
+
21
78
## [sqlcmd (ODBC)](#tab/odbc)
22
79
23
-
The `-G` option is used by **sqlcmd** (ODBC) when connecting to Azure SQL Database or Azure Synapse Analytics, to specify that the user be authenticated using Azure AD authentication. This option sets the **sqlcmd** scripting variable `SQLCMDUSEAAD=true`.
80
+
The `-G` option is used by **sqlcmd** (ODBC) when connecting to Azure SQL Database or Azure Synapse Analytics, to specify that the user be authenticated using Microsoft Entra authentication. This option sets the **sqlcmd** scripting variable `SQLCMDUSEAAD=true`.
24
81
25
-
- The `-G` option requires at least **sqlcmd** version [13.1](https://go.microsoft.com/fwlink/?LinkID=825643). Azure AD interactive authentication requires **sqlcmd** (ODBC) [version 15.0.1000.34](sqlcmd-utility.md#download-and-install-sqlcmd) and later versions, as well as [ODBC version 17.2 and later versions](../../connect/odbc/download-odbc-driver-for-sql-server.md).
82
+
- The `-G` option requires at least **sqlcmd** version [13.1](https://go.microsoft.com/fwlink/?LinkID=825643). Microsoft Entra interactive authentication requires **sqlcmd** (ODBC) [version 15.0.1000.34](sqlcmd-utility.md#download-and-install-sqlcmd) and later versions, as well as [ODBC version 17.2 and later versions](../../connect/odbc/download-odbc-driver-for-sql-server.md).
26
83
27
-
-Azure AD integrated authentication requires [Microsoft ODBC Driver 17 for SQL Server](../../connect/odbc/download-odbc-driver-for-sql-server.md) version 17.6.1 and later versions, and a properly [configured Kerberos environment](../../connect/odbc/linux-mac/using-integrated-authentication.md).
84
+
-Microsoft Entra integrated authentication requires [Microsoft ODBC Driver 17 for SQL Server](../../connect/odbc/download-odbc-driver-for-sql-server.md) version 17.6.1 and later versions, and a properly [configured Kerberos environment](../../connect/odbc/linux-mac/using-integrated-authentication.md).
28
85
29
86
- The `-G` option only applies to Azure SQL Database and Azure Synapse Analytics.
30
87
31
-
-Azure AD interactive authentication isn't currently supported on Linux or macOS.
88
+
-Microsoft Entra interactive authentication isn't currently supported on Linux or macOS.
32
89
33
90
To determine your version, execute `sqlcmd "-?"`. For more information, see [Connecting to SQL Database or Azure Synapse Analytics By Using Azure Active Directory Authentication](/azure/azure-sql/database/authentication-aad-overview). The `-A` option isn't supported with the `-G` option.
34
91
35
-
### Azure Active Directory username and password
92
+
### Microsoft Entra username and password
36
93
37
-
When you want to use an Azure AD user name and password, you can provide the `-G` option with the user name and password, by using the `-U` and `-P` options.
94
+
When you want to use an Microsoft Entra user name and password, you can provide the `-G` option with the user name and password, by using the `-U` and `-P` options.
@@ -63,13 +120,13 @@ SERVER = Target_DB_or_DW.testsrv.database.windows.net;Authentication=ActiveDirec
63
120
> [!NOTE]
64
121
> The `-E` option (`Trusted_Connection`) cannot be used along with the `-G` option.
65
122
66
-
### Azure Active Directory interactive authentication
123
+
### Microsoft Entra interactive authentication
67
124
68
-
The Azure AD interactive authentication for Azure SQL Database and Azure Synapse Analytics, allows you to use an interactive method supporting multi-factor authentication. For more information, see [Active Directory Interactive Authentication](../../ssdt/azure-active-directory.md#active-directory-interactive-authentication).
125
+
The Microsoft Entra interactive authentication for Azure SQL Database and Azure Synapse Analytics, allows you to use an interactive method supporting multi-factor authentication. For more information, see [Active Directory Interactive Authentication](../../ssdt/azure-active-directory.md#active-directory-interactive-authentication).
69
126
70
127
To enable interactive authentication, provide the `-G` option with user name (`-U`) only, without a password.
71
128
72
-
The following example exports data using Azure AD interactive mode, indicating a username where the user represents an Azure AD account. This is the same example used in the previous section, **Azure Active Directory username and password**.
129
+
The following example exports data using Microsoft Entra interactive mode, indicating a username where the user represents a Microsoft Entra account. This is the same example used in the previous section, **Microsoft Entra username and password**.
73
130
74
131
Interactive mode requires manually entering a password, or for accounts with multi-factor authentication enabled, complete your configured MFA authentication method.
75
132
@@ -83,75 +140,20 @@ The previous command generates the following connection string in the backend:
83
140
SERVER = Target_DB_or_DW.testsrv.database.windows.net;UID=alice@aadtest.onmicrosoft.com;AUTHENTICATION=ActiveDirectoryInteractive
84
141
```
85
142
86
-
In case an Azure AD user is a domain federated user using a Windows account, the user name required in the command-line contains its domain account (for example `joe@contoso.com`):
143
+
In case a Microsoft Entra user is a domain federated user using a Windows account, the user name required in the command-line contains its domain account (for example `joe@contoso.com`):
If guest users exist in a specific Azure AD tenant, and are part of a group that exists in Azure SQL Database that has database permissions to execute the **sqlcmd** command, their guest user alias is used (for example, `keith0@adventureworks.com`).
149
+
If guest users exist in a specific Microsoft Entra tenant, and are part of a group that exists in Azure SQL Database that has database permissions to execute the **sqlcmd** command, their guest user alias is used (for example, `keith0@adventureworks.com`).
93
150
94
151
> [!IMPORTANT]
95
152
> There is a known issue when using the `-G` and `-U` option with **sqlcmd** (ODBC), where putting the `-U` option before the `-G` option may cause authentication to fail. Always start with the `-G` option followed by the `-U` option.
96
153
97
-
## [sqlcmd (Go)](#tab/go)
98
-
99
-
**sqlcmd** (Go) supports more Azure AD authentication models, based on the [azidentity package](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). The implementation relies on an Azure AD connector in the [go-sqlcmd driver](https://github.com/microsoft/go-mssqldb).
100
-
101
-
### Command line arguments
102
-
103
-
To use Azure AD authentication, you can use one of two command line switches.
104
-
105
-
`-G` is (mostly) compatible with its usage in **sqlcmd** (ODBC). If a username and password are provided, it authenticates using Azure AD Password authentication. If a user name is provided, it uses Azure AD Interactive authentication, which may display a web browser. If no username or password is provided, it uses a `DefaultAzureCredential`, which attempts to authenticate through various mechanisms.
106
-
107
-
`--authentication-method=` can be used to specify one of the following authentication types.
108
-
109
-
#### ActiveDirectoryDefault
110
-
111
-
- For an overview of the types of authentication this mode uses, see [Default Azure Credential](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/azidentity#defaultazurecredential).
112
-
- Choose this method if your database automation scripts are intended to run in both local development environments and in a production deployment in Azure. In your development environment, you can use a client secret or an Azure CLI login. Without changing the script from the development environment, you can use a managed identity or client secret on your production deployment.
113
-
- Setting environment variables `AZURE_TENANT_ID` and `AZURE_CLIENT_ID` are necessary for `DefaultAzureCredential` to begin checking the environment configuration and look for one of the following additional environment variables in order to authenticate:
114
-
- Setting environment variable `AZURE_CLIENT_SECRET` configures the `DefaultAzureCredential` to choose `ClientSecretCredential`.
115
-
- Setting environment variable `AZURE_CLIENT_CERTIFICATE_PATH` configures the `DefaultAzureCredential` to choose `ClientCertificateCredential` if `AZURE_CLIENT_SECRET` isn't set.
116
-
- Setting environment variable AZURE_USERNAME configures the `DefaultAzureCredential` to choose `UsernamePasswordCredential` if `AZURE_CLIENT_SECRET` and `AZURE_CLIENT_CERTIFICATE_PATH` aren't set.
117
-
118
-
#### ActiveDirectoryIntegrated
119
-
120
-
This method is currently not implemented, and falls back to `ActiveDirectoryDefault`.
121
-
122
-
#### ActiveDirectoryPassword
123
-
124
-
- This method authenticates using a username and password. It doesn't work if MFA is required.
125
-
126
-
- You provide the user name and password using the usual command line switches or `SQLCMD` environment variables.
127
-
128
-
- Set `AZURE_TENANT_ID` environment variable to the tenant ID of the server if not using the default tenant of the user.
129
-
130
-
#### ActiveDirectoryInteractive
131
-
132
-
This method launches a web browser to authenticate the user.
133
-
134
-
#### ActiveDirectoryManagedIdentity
135
-
136
-
Use this method when running **sqlcmd** (Go) on an Azure VM that has either a system-assigned or user-assigned managed identity. If using a user-assigned managed identity, set the user name to the ID of the managed identity. If using a system-assigned identity, leave user name empty.
137
-
138
-
#### ActiveDirectoryServicePrincipal
139
-
140
-
This method authenticates the provided user name as a service principal ID and the password as the client secret for the service principal. Provide a user name in the form `<service principal id>@<tenant id>`. Set `SQLCMDPASSWORD` variable to the client secret. If using a certificate instead of a client secret, set `AZURE_CLIENT_CERTIFICATE_PATH` environment variable to the path of the certificate file.
141
-
142
-
### Environment variables for Azure AD authentication
143
-
144
-
Some Azure AD authentication settings don't have command line inputs, and some environment variables are consumed directly by the `azidentity` package used by **sqlcmd** (Go).
145
-
146
-
These environment variables can be set to configure some aspects of Azure AD authentication and to bypass default behaviors. In addition to the variables listed previously, the following are specific to **sqlcmd** (Go), and apply to multiple methods.
147
-
148
-
#### SQLCMDCLIENTID
149
-
150
-
Set this environment variable to the identifier of an application registered in your Azure AD, which is authorized to authenticate to Azure SQL Database. Applies to `ActiveDirectoryInteractive` and `ActiveDirectoryPassword` methods.
151
-
152
154
---
153
155
154
-
## Next steps
156
+
## Related content
155
157
156
158
-[sqlcmd utility](sqlcmd-utility.md)
157
159
-[sqlcmd - Start the utility](sqlcmd-start-utility.md)
Copy file name to clipboardExpand all lines: docs/tools/sqlcmd/sqlcmd-utility.md
+5-3Lines changed: 5 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -43,10 +43,10 @@ The **sqlcmd** utility lets you enter Transact-SQL statements, system procedures
43
43
44
44
There are two versions of **sqlcmd**:
45
45
46
-
- The ODBC-based **sqlcmd**, available with [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] or the Microsoft Command Line Utilities, and part of the `mssql-tools` package on Linux.
47
-
48
46
- The `go-mssqldb`-based **sqlcmd**, sometimes styled as **go-sqlcmd**. This version is a standalone tool you can download independently of [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)].
49
47
48
+
- The ODBC-based **sqlcmd**, available with [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] or the Microsoft Command Line Utilities, and part of the `mssql-tools` package on Linux.
49
+
50
50
To determine the version you have installed, run the following statement at the command line:
51
51
52
52
::: zone pivot="cs1-bash"
@@ -99,7 +99,9 @@ Copyright (C) 2022 Microsoft Corporation. All rights reserved.
99
99
100
100
You may have several versions of **sqlcmd** (ODBC) installed on your computer. Be sure you're using the correct version. You should have at least version 15.0.4298.1 installed.
101
101
102
-
Always Encrypted (`-g`) and Azure AD authentication (`-G`) require at least version 13.1.
102
+
Always Encrypted (`-g`) and Microsoft Entra authentication (`-G`) require at least version 13.1.
0 commit comments