dotConnect for Snowflake supports four authentication methods. To select a method, set the Authentication Type connection string parameter or the SnowflakeConnectionStringBuilder.AuthenticationType property.
Authentication Type |
Description |
Required parameters |
|---|---|---|
| Basic | Signs in with the user name and a programmatic access token (PAT) or a password. This is the default method. In the connection dialogs, it is called Programmatic Access Token. | User, Password |
| KeyPair | Signs in with an RSA key pair. The public key is assigned to the user in Snowflake, and the private key is passed in the connection string. | User, Private Key |
| OAuth2 | Signs in with an OAuth 2.0 refresh token issued by a Snowflake OAuth security integration. | Refresh Token, Client Id, Client Secret |
| OAuth2Interactive | Signs in as OAuth2. If Refresh Token is empty, the provider first opens a browser to sign in to Snowflake and gets the refresh token. See Interactive Sign-In. | Client Id, Client Secret |
For all methods, you also need to specify the Domain parameter. We also recommend that you specify the Database parameter. The provider connects without it, but the connection dialog of Server Explorer in Visual Studio requires it. For more information, see Connecting to Snowflake.
Specify the login name of the Snowflake user in the User parameter and a programmatic access token (PAT) of the user in the Password parameter. Snowflake accepts a programmatic access token in place of the password. A password works only for users who aren't required to use multi-factor authentication (MFA) when they sign in with a password. For information on how to generate a token, see Using programmatic access tokens for authentication in the Snowflake documentation.
Domain=myorg-myaccount;Database=your_database;Warehouse=your_warehouse;User=your_user;Password=your_token;License Key=********** |
In the Add Connection dialog in Visual Studio, select Programmatic Access Token in the Authentication list, enter the user name, and enter the token in the Password (PAT) field.

For applications and services, use a programmatic access token, key-pair authentication, or OAuth authentication instead of a password.
With key-pair authentication, dotConnect for Snowflake signs a JSON Web Token (JWT) with the private key of the user and sends it to Snowflake instead of a password. To use this method:
-nocrypt option. OpenSSL prompts for a passphrase.-----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- lines:
Assigning a public key requires the SECURITYADMIN role or a role with the OWNERSHIP privilege on the user.The Private Key parameter takes either the private key itself or the path to the key file. If the value contains -----BEGIN, it is treated as the key; otherwise, it is treated as a path to an existing file. The key must be in the PEM format, including the -----BEGIN ... PRIVATE KEY----- and -----END ... PRIVATE KEY----- lines. Both PKCS#8 keys (BEGIN PRIVATE KEY, BEGIN ENCRYPTED PRIVATE KEY) and PKCS#1 keys (BEGIN RSA PRIVATE KEY) are supported. If you write the key in a connection string, enclose it in double quotes and keep its line breaks.
In the Add Connection dialog in Visual Studio, select Key-pair in the Authentication list, enter the user name, and enter the private key or click the ellipsis (...) to select the key file. If the key is encrypted, also enter the passphrase.

Because the key spans several lines, it is easier to set it with the SnowflakeConnectionStringBuilder class than to write it in the connection string manually:
dotConnect for Snowflake takes the account name for the JWT from the Domain parameter: it is the part of the host name before the first dot. For example, for myorg-myaccount.snowflakecomputing.com, the account name is MYORG-MYACCOUNT.
If the key cannot be read, the following exception is thrown: Could not read the private key. Check the passphrase and that Private Key is an RSA key in PEM format (PKCS#1 or PKCS#8, starting with -----BEGIN) or the path to such a file. Check that the key is complete, that it is in the PEM format, and that the passphrase is correct.
If the value of Private Key doesn't contain -----BEGIN and there is no file at this path, the following exception is thrown: Private Key must be an RSA key in PEM format (starting with -----BEGIN) or the path to an existing key file; the file '<path>' was not found.
With OAuth 2.0 authentication, dotConnect for Snowflake exchanges a refresh token for an access token when it opens a connection and uses the access token to sign in. When the access token expires, the provider gets a new one automatically.
To use this method, you need an OAuth client registered in Snowflake as a security integration, and a refresh token issued for this client:
The refresh token is valid for the period set in the OAUTH_REFRESH_TOKEN_VALIDITY property of the integration. When the refresh token expires, get a new one.
If you set Authentication Type to OAuth2Interactive, leave Refresh Token empty, and open a connection in an application that can show a browser (not in a Windows service), dotConnect for Snowflake gets the refresh token itself:
Domain=myorg-myaccount;Database=your_database;Warehouse=your_warehouse;Authentication Type=OAuth2Interactive;Client Id=your_client_id;Client Secret=your_client_secret;License Key=********** |
http://localhost:58088, where the provider waits for the authorization code.If Refresh Token is specified, an OAuth2Interactive connection signs in in the same way as an OAuth2 connection and doesn't open a browser. With Authentication Type set to OAuth2, the provider never opens a browser, and an empty Refresh Token causes an error.
In a process that can't show a browser, an OAuth2Interactive connection with an empty Refresh Token throws the following exception: Refresh Token cannot be empty for the OAuth2Interactive authentication type in a non-interactive process: the sign-in to Snowflake needs a browser. Sign in once in an interactive application (the Connect dialog in Visual Studio or Entity Developer) and put the Refresh Token it gets into the connection string.
In the Add/Modify Connection dialog in Visual Studio, the Authentication list shows both OAuth2 and OAuth2Interactive as OAuth 2.0. The Sign in to Snowflake button starts the same sign-in, fills out Refresh Token, and sets Authentication Type to OAuth2Interactive in the connection string.

The following requirements apply:
http://localhost:58088, without a trailing slash, and OAUTH_ALLOW_NON_TLS_REDIRECT_URI must be TRUE, because the redirect URI uses http.For all authentication methods, you can specify the Warehouse and Role connection string parameters. If they are not set, Snowflake uses the default warehouse and the default role of the user. To execute queries, the session needs a running or auto-resumable warehouse and a role that has the USAGE privilege on this warehouse.
Follow these recommendations to secure Snowflake connections and protect authentication credentials:
For help with authentication and connection issues, see Troubleshooting.