snowflake-connector-net icon indicating copy to clipboard operation
snowflake-connector-net copied to clipboard

Can't open connection in .Net Core project

Open borysl opened this issue 5 years ago • 7 comments

Issue description

Looks the same as in https://github.com/snowflakedb/snowflake-connector-net/issues/11 Take the example from the README and try to run Receive task has been cancelled on connection opened;

Example code

        static void Main(string[] args)
        {
            using (IDbConnection conn = new SnowflakeDbConnection())
            {
                var connectionString = "...";
                conn.ConnectionString = connectionString;
                conn.Open(); // Fails here

                IDbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select * from META_DATA.LOG_MESSAGES order by LOG_TS desc limit 10";
                IDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Console.WriteLine(reader.GetString(0));
                }

                conn.Close();
            }
        }

Error log

   at Snowflake.Data.Client.SnowflakeDbConnection.Open()
   at SFClient.Program.Main(String[] args) in C:\fenix-data\SFClient\Program.cs:line 15

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

Configuration

Driver version: 1.0.13 Dotnet framework and version: .Net Core 2.2.300 Server version: 3.36.3 Client OS: Windows 10

borysl avatar Aug 14 '19 08:08 borysl

2019-08-14_11h17_41

How it looks in my environment

borysl avatar Aug 14 '19 08:08 borysl

I think it should be related to OCSP. .NET connector should also implement fail-open/fail-close configuration similar to other connector.

initHttpClient() in HttpUtil.cs, HttpClientHandler initialization can change as bellow

var handler = new HttpClientHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Manual; // if allow fail-open add the following code handler.ServerCertificateCustomValidationCallback = delegate { return true; }; var client = new HttpClient(handler);

urbrioche avatar Sep 06 '19 13:09 urbrioche

image

I believe it's because you are missing a semicolon at the end of schema=META_DATA" try adding schema=META_DATA;" and check if your connection string separates values with semicolon

Janatbek avatar Oct 04 '19 18:10 Janatbek

Is there any solution to this issue?

KoditkarVedant avatar Nov 07 '19 16:11 KoditkarVedant

I just had the same issue, triple check your connection string. Mine was missing HOST=MY_ACCOUNT_NAME.eu-central-1.snowflakecomputing.com. The default region is us-west so conn.Open();was hanging forever

If it helps anyone, I am using Snowflake.Data v1.1.0 and Microsoft.AspNetCore.All v2.1.9

yannickvidal avatar Feb 13 '20 15:02 yannickvidal

I was having the same problem, and I figured it was my connection string. What wasn't clear was that you have to type the account AND retype it in the host. If your account is "myComp" and hosted in west Europe Azure (for example) then your connection string would be something like account=myComp;host=myComp.west-europe.azure.snowflakecomputing.com;user=myUser;password=myPassword;db=myDB;warehouse=MYWH;role=sec_role;"

NJarZe avatar Jul 13 '20 19:07 NJarZe

We were facing the same error when running the code in a docker container in Linux, we added the ServerCertificateCustomValidationCallback for the HttpClientHandler being used during client initialization inside the library and logged the validation errors.

We were getting a RemoteCertificateNameMismatch policy status error but everything else was good. After looking at this issue https://github.com/dotnet/runtime/issues/35880 we confirmed that it was the case for us, our connection string was like MyCompany_Dev.us-east-1.snoflakecomputing,com, snowflake supports dashes instead of underscores automatically, so, when we changed our connection string to MyCompany-Dev.us-east-1.snowflakecomputing.com we were able to connect with no issues in Linux.

JorgeArellano avatar Sep 15 '20 18:09 JorgeArellano

To clean up and re-prioritize more pressing bugs and feature requests we are closing all issues older than 6 months as of April 1, 2023. If there are any issues or feature requests that you would like us to address, please create them according to the new templates we have created. For urgent issues, opening a support case with this link Snowflake Community is the fastest way to get a response.

sfc-gh-jtang avatar May 25 '23 17:05 sfc-gh-jtang