dotConnect for Snowflake Documentation
On this page
    Troubleshooting
    On this page

    Learn how dotConnect for Snowflake handles errors and how to troubleshoot common connection, query execution, transaction, and Entity Framework Core issues.

    Handling Errors

    dotConnect for Snowflake throws a SnowflakeException for errors returned by Snowflake, as well as login and network errors. In addition to the Message property, SnowflakeException provides the following properties:

    For errors that dotConnect for Snowflake detects before sending a request, the provider throws standard .NET exceptions:

    Exception

    Description

    ArgumentExceptionAn argument, such as the connection string, is invalid.
    InvalidOperationExceptionThe operation isn't valid in the current state.
    NotSupportedExceptionThe requested feature isn't supported. For more information, see Usage Considerations.

    The following example shows how to handle exceptions based on their error codes:

    try {
      using (SnowflakeCommand command = new SnowflakeCommand("SELECT * FROM dept", connection))
      using (SnowflakeDataReader reader = command.ExecuteReader()) {
        while (reader.Read())
          Console.WriteLine(reader.GetValue(0));
      }
    }
    catch (SnowflakeException ex) {
      switch (ex.ErrorCode) {
        case 2003:  // SQLSTATE 42S02: the object doesn't exist or the role has no privileges on it
          Console.WriteLine("Check the table name and the privileges of the role: " + ex.Message);
          break;
        case 604:   // SQLSTATE 57014: the statement was canceled
          Console.WriteLine("The query was canceled.");
          break;
        default:
          Console.WriteLine("Error {0} ({1}): {2}", ex.ErrorCode, ex.SqlState, ex.Message);
          break;
      }
    }
    
    Try
      Using command As New SnowflakeCommand("SELECT * FROM dept", connection)
        Using reader As SnowflakeDataReader = command.ExecuteReader()
          While reader.Read()
            Console.WriteLine(reader.GetValue(0))
          End While
        End Using
      End Using
    Catch ex As SnowflakeException
      Select Case ex.ErrorCode
        Case 2003  ' SQLSTATE 42S02: the object doesn't exist or the role has no privileges on it
          Console.WriteLine("Check the table name and the privileges of the role: " & ex.Message)
        Case 604   ' SQLSTATE 57014: the statement was canceled
          Console.WriteLine("The query was canceled.")
        Case Else
          Console.WriteLine("Error {0} ({1}): {2}", ex.ErrorCode, ex.SqlState, ex.Message)
      End Select
    End Try
    

    Automatic Retries and Session Renewal

    dotConnect for Snowflake automatically recovers from certain failures without returning an error to the application:

    If a session expires during an active transaction, the transaction can't continue in a new session. For more information, see Transaction Issues.

    Connection Issues

    Use the following table to troubleshoot errors that occur when opening a connection.

    Error

    Cause and resolution

    The remote server returned an error: (404) Not Found. The Domain connection string parameter doesn't point to an existing Snowflake account. Check the account identifier and its format. For more information, see Preparing Snowflake for Connection.
    A timeout or a name resolution error while connecting The Snowflake host is unreachable. Check your network connection and firewall settings. If you connect through a proxy server, specify the proxy connection string parameters. To identify the hosts to allow through the firewall, run SELECT SYSTEM$ALLOWLIST() in Snowflake.
    Login failed. Error: JWT token is invalid.
    (ErrorCode 390144)
    Key-pair authentication failed. The user specified in the User parameter doesn't exist, no public key is assigned to the user, or the assigned public key doesn't match the private key. Compare the fingerprint of the key with the RSA_PUBLIC_KEY_FP value returned by DESC USER. For more information, see Key-Pair Authentication.
    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. The passphrase is incorrect, or the value of the Private Key parameter is not a complete RSA key in the PEM format. If the key is encrypted, specify the Passphrase parameter. If you pass the key itself in the connection string, enclose the value in quotes and keep its line breaks.
    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. The Private Key parameter contains a path to a file that doesn't exist. Check the path. The provider resolves relative paths against the application's current directory.
    Login failed. Error: Role '<role>' specified in the connect string does not exist or not authorized.
    (ErrorCode 390189)
    The role specified in the Role parameter doesn't exist or isn't granted to the user. Grant the role with GRANT ROLE <role> TO USER <user>, or remove the Role parameter to use the default role of the user.
    Login failed. Error: The requested database does not exist or not authorized.
    (ErrorCode 390201)
    The database specified in the Database parameter doesn't exist, or the role has no USAGE privilege on it. Unquoted names are case-insensitive; a name in double quotes must match the case exactly.
    Login failed. Error: The requested warehouse does not exist or not authorized.
    (ErrorCode 390201)
    The warehouse specified in the Warehouse parameter doesn't exist, or the role has no USAGE privilege on it.
    Connection parameter '<name>' is duplicated.
    (ArgumentException)
    The connection string contains a duplicate parameter. Remove the duplicate entry.
    License errors See Technical licensing in the FAQ.

    Query Execution Issues

    Use the following table to troubleshoot errors that occur when executing a command.

    Error

    Cause and resolution

    SQL compilation error: Object '<name>' does not exist or not authorized.
    (ErrorCode 2003, SqlState 42S02)

    The table or view doesn't exist, or the role has no privileges on it. Check the following:

    • The name. Snowflake converts unquoted identifiers to upper case, and a name in double quotes is case-sensitive: a table created as "Dept" can't be queried as Dept.
    • The database and schema. An unqualified name refers to the current database and schema of the session, which are set by the Database and Schema connection string parameters. Specify them or qualify the name: database.schema.table.
    • The privileges of the role. The role needs USAGE on the database and the schema and the required privilege on the object.
    No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.
    (ErrorCode 606, SqlState 57P03)
    A query that needs compute resources is executed in a session that has no current warehouse, for example, because neither the connection string nor the user specifies a warehouse, or because the current warehouse was dropped. Specify the Warehouse connection string parameter or set a default warehouse for the user: ALTER USER <user> SET DEFAULT_WAREHOUSE = <warehouse>.
    SQL compilation error: syntax error line <n> at position <n> unexpected '<token>'.
    (ErrorCode 1003, SqlState 42000)
    The statement contains invalid SQL syntax. dotConnect for Snowflake sends statements to Snowflake without modification, so they must use the Snowflake SQL dialect.
    Actual statement count 2 did not match the desired statement count 1.
    (ErrorCode 8, SqlState 0A000)
    The command text contains several statements separated by semicolons. Use a separate command for each statement.
    The timeout period elapsed prior to completion of the operation or the server is not responding. The statement didn't complete within the CommandTimeout of the command (3600 seconds by default). The statement is aborted on the server. Increase CommandTimeout or optimize the query; a larger warehouse also reduces the execution time. For more information, see Command Timeouts and Cancellation.
    SQL execution canceled
    (ErrorCode 604, SqlState 57014)
    The statement was canceled with the Cancel method of the command or with the CancellationToken passed to an asynchronous method. The provider reports cancellation by throwing a SnowflakeException rather than an OperationCanceledException.
    Numeric value '<value>' is not recognized
    (ErrorCode 100038, SqlState 22018)

    Division by zero
    (ErrorCode 100051, SqlState 22012)
    SQLSTATE class 22 indicates a data error, such as a failed value conversion or an invalid arithmetic operation. Check the input data and parameter types.
    The result format '<format>' is not supported; the session must return JSON results The DOTNET_QUERY_RESULT_FORMAT session parameter was changed, for example, with ALTER SESSION. dotConnect for Snowflake reads results in the JSON format only. To restore the required format, run ALTER SESSION SET DOTNET_QUERY_RESULT_FORMAT = 'JSON'.
    Stored procedures are not supported in Snowflake.
    (NotSupportedException)
    The CommandType property is set to StoredProcedure. To execute a stored procedure, set CommandType to Text and use the CALL statement, for example, CALL my_procedure(:p1). For details, see Using Stored Procedures and Functions.
    Specified method is not supported.
    (NotSupportedException)
    The Direction property of a parameter is set to Output, InputOutput, or ReturnValue, directly or in the SnowflakeParameter constructor. Output parameters aren't supported: get the result of a procedure with ExecuteScalar or ExecuteReader. For details, see Return Values and Output Parameters.
    SQL compilation error: Unsupported data type 'VARIANT'.
    (ErrorCode 2040, SqlState 42601)
    A command has a parameter of the Variant, Object, or Array type, for example, when a data adapter inserts or updates a VARIANT, OBJECT, or ARRAY value with commands generated by the command builder. Parameters of these types aren't supported. Pass the JSON text in a String parameter and convert it with PARSE_JSON; for a data adapter, define your own InsertCommand and UpdateCommand that do it. For details, see Update Semi-Structured Data Using a Data Adapter.
    SQL compilation error: Invalid expression [PARSE_JSON(:p)] in VALUES clause
    (ErrorCode 2014, SqlState 22000)

    SQL compilation error: Expression type does not match column data type, expecting VARIANT but got VARCHAR
    (ErrorCode 2023, SqlState 22000)
    The VALUES clause of an INSERT statement contains PARSE_JSON or a similar function, or a parameter value is inserted into a VARIANT, OBJECT, or ARRAY column without PARSE_JSON, with INSERT ... VALUES or INSERT ... SELECT. Parameter values are sent as text, even if the parameter type is Variant, Object, or Array. Use the INSERT ... SELECT form with PARSE_JSON. For details, see Write Semi-Structured Values.
    SQL compilation error: Expression type does not match column data type, expecting TIMESTAMP_NTZ(9) but got TIMESTAMP_TZ(9) for column <column>

    SQL compilation error: Expression type does not match column data type, expecting TIMESTAMP_LTZ(9) but got TIMESTAMP_TZ(9) for column <column>
    A DateTimeOffset parameter is sent as a TIMESTAMP_TZ value. Snowflake doesn't implicitly convert this value when writing it to a TIMESTAMP_NTZ or TIMESTAMP_LTZ column. To resolve the issue, cast the parameter in the SQL statement, for example, :value::TIMESTAMP_NTZ or :value::TIMESTAMP_LTZ. Alternatively, for a TIMESTAMP_LTZ column, set the Type property of the parameter to TimestampLTZ. For more information, see Date and Time Values.
    Batch updates are not supported yet The UpdateBatchSize property of a data adapter is greater than 1. Set it to 1. To load large amounts of data, use bulk data loading.

    Transaction Issues

    Error

    Cause and resolution

    The connection already has an active transaction. Snowflake does not support nested transactions.
    (InvalidOperationException)
    BeginTransaction is called while a transaction of the connection is open. Commit or roll back the active transaction before starting a new one.
    Snowflake supports the ReadCommitted isolation level only; <level> was requested.
    (NotSupportedException)
    BeginTransaction is called with an isolation level other than ReadCommitted or Unspecified. Use one of these levels.
    The Snowflake session expired while a transaction was open, and a new login would start a new session. The transaction is lost and its changes are not committed; roll it back and run it again.

    The transaction was lost: the Snowflake session it ran in has ended (it expired, or the connection logged out). Its changes were not committed.
    The Snowflake session ended while a transaction was open, so the transaction was lost with it. Roll back the transaction and run it again. Keep transactions short and avoid leaving them open while waiting for user input.
    Note Executing a DDL statement, such as CREATE TABLE, implicitly commits the active transaction. For details about transactions, see Modifying Data Overview.

    Entity Framework Core Issues

    Error

    Cause and resolution

    SQL compilation error: error line <n> at position <n> invalid identifier '<NAME>'
    (ErrorCode 904, SqlState 42000)

    SQL compilation error: Object '<NAME>' does not exist or not authorized.
    (ErrorCode 2003, SqlState 42S02)
    A possible cause is that a raw SQL query references case-sensitive database objects created by Entity Framework Core without double quotation marks. Snowflake converts unquoted identifiers to uppercase. Enclose object names in double quotation marks and match their original case, for example, SELECT "Name" FROM "Products". For more information, see Names of Database Objects.
    The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded.
    (DbUpdateConcurrencyException)
    The database operation affected fewer rows than expected. The row might have been deleted or modified after the entity was loaded. Reload the affected entity, resolve the concurrency conflict, and retry the operation if appropriate. For more information, see Handling Concurrency Conflicts in the Entity Framework Core documentation.
    Snowflake cannot evaluate a correlated subquery with LIMIT or OFFSET ("Unsupported subquery type cannot be evaluated"): First, FirstOrDefault, Single, Take or Skip on the related rows inside the projection or the filter of another query. ...
    (NotSupportedException)
    The LINQ query generates a correlated subquery that uses LIMIT or OFFSET, which Snowflake can't evaluate in this context. Where applicable, rewrite the query using aggregate functions such as Min, Max, or Count. Alternatively, retrieve related data in a separate query or load the required data and process it on the client. For more information, see LINQ to Entities.
    The Snowflake EF Core provider does not generate idempotent migration scripts: DDL commits on its own in Snowflake. Generate the script from a known migration instead.
    (NotSupportedException)
    dotConnect for Snowflake doesn't support generating idempotent migration scripts. This error occurs when you specify the --idempotent option of the dotnet ef migrations script command. Generate a script for a known range of migrations instead. For example, dotnet ef migrations script InitialCreate AddOrders generates the statements of the migrations after InitialCreate up to AddOrders. For more information, see Migrations.

    Diagnosing Issues

    If the issue persists, contact Devart support. For more information, see Getting Support.