snowflakedb / snowflake-connector-net

Snowflake Connector for .NET
Apache License 2.0
180 stars 139 forks source link

Can't execute command when connection has never been opened #584

Closed dharmenbavaria closed 1 year ago

dharmenbavaria commented 1 year ago

Issue description

We are getting this error on production code with the exception message "Can't execute a command when the connection has never been opened", I have no clue why the SFSession state is null.

Situation We have a different repository for create, update and delete, and for every method execution, we create a connection execute the query and close the connection.

Locally we never have this issue only in production code.

Example code

using (IDbConnection conn = new SnowflakeDbConnection())
{
    conn.ConnectionString = "***";

    conn.Open();
   // running a query
    conn.Close();
}

Error log


 Can't execute command when connection has never been opened 
          at Snowflake.Data.Client.SnowflakeDbCommand.SetStatement()
         at Snowflake.Data.Client.SnowflakeDbCommand.ExecuteInternal(Boolean describeOnly)
         at Snowflake.Data.Client.SnowflakeDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
         at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()

There is an example in READMD.md file showing you how to enable logging.

Configuration

Driver version: 2.17.0 Dotnet framework and version: E.g. .net framework 4.5.2 or .net standard 2.0 .net 6.0 Server version: 7.2.0

Client OS: Linux container mcr.microsoft.com/dotnet/aspnet:6.0

mbwilding commented 1 year ago

Add this to your connection string.

insecuremode=true

turbodavidson commented 1 year ago

Has there been any movement on or confirmation of this bug? We are experiencing the same issue, but always after one succesful query...

        using var conn = new SnowflakeDbConnection(connectionString);
        using var cmd = conn.CreateCommand();
        cmd.CommandText = $"<query>";
        conn.Open();
        using var reader = cmd.ExecuteReader();
        if (reader.Read()) {
            return reader.GetValue();
        }
        return null;
sfc-gh-dszmolka commented 1 year ago

hello and thank you for raising this issue, also apologies for the long period without response. we'll take a look

sfc-gh-dszmolka commented 1 year ago

this issue seems to be related to some connection pool errors which were there indeed with earlier driver versions like 2.0.17 but in the latest one 2.0.25 this should be fixed. Please upgrade to the latest driver and retest - let us know if you still see the same error. Probably we'll require you to share the debug logs with the reproduction as well.

luizs81 commented 1 year ago

This is still happening with the Snowflake.Data nuget package 2.1.3.

sfc-gh-dszmolka commented 1 year ago

since we couldn't reproduce it even with 2.0.25 (after all the connection pool fixes), if the issue still occurs for you guys, can someone who still has this issue with the latest Snowflake driver please open a new issue in this repo with a reproducible code example ? Thank you in advance !