snowflake-connector-net
snowflake-connector-net copied to clipboard
SNOW-153578: Bad DB or Schema in Connection String still allows for connections, crashes app when used.
Issue description
A database connection string that is completely valid but contains a nonexistent database name, schema name, or both still allows for connectivity to be made and opened. Then, upon using this connection, throws a whole lot of errors that result in a crash.
Example code
This works fine:
var conn = var conn = new SnowflakeDbConnection {ConnectionString = database.connectionString}; // where database.connectionString is a valid connection string but contains a nonexistent db or schema
await conn.OpenAsync();
sqlCommand.CommandTimeout = commandTimeout;
Then, this fails spectacularly
await using var reader = await sqlCommand.ExecuteReaderAsync(cancellationToken);
Error log
Wrapping the above line in a try/catch handles one exception, but many more come thereafter. The ones that come after result in an AggregateException
. I can add that stack trace if desired, but it's quite messy and contains little or useful data.
System.OperationCanceledException: The operation was canceled.
at Snowflake.Data.Core.RestRequester.SendAsync(HttpRequestMessage request, TimeSpan timeoutPerRestRequest, CancellationToken externalCancellationToken)
at Snowflake.Data.Core.RestRequester.PostAsync[T](IRestRequest request, CancellationToken cancellationToken)
at Snowflake.Data.Core.SFStatement.ExecuteAsync(Int32 timeout, String sql, Dictionary`2 bindings, Boolean describeOnly, CancellationToken cancellationToken)
at Snowflake.Data.Client.SnowflakeDbCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
There is an example in READMD.md file showing you how to enable logging.
Configuration
Driver version: <PackageReference Include="Snowflake.Data" Version="1.1.2" />
Dotnet framework and version: .net core 3.1
Server version: 4.12.3 You may get the server version by running a query:
SELECT CURRENT_VERSION();
Client OS: MacOS Catalina 10.15.4
The StackOverflow post I posted about this led me to post this issue too.
I also ran into this issue yesterday. Our connection string was correct, but the environment we were running the app in did not have the network opened to be able to connect to Snowflake. There was no failure around opening the connection using:
var conn = new SnowflakeDbConnection();
conn.ConnectionString = _connectionString;
await conn.OpenAsync();
Wasn't until our code went to execute a query that the w3wp process crashed. Are there any other workarounds or just what was outlined in the Stack Overflow post from @alexrosenfeld10 above?
@dnawnOlo I've been going around adding SELECT 1;
statements to my applications for their k8s readiness probes. You might consider doing the same.
I also just posted https://github.com/snowflakedb/snowflake-connector-net/issues/292 yesterday 😅
We are looking into this one.
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.
Ofcourse it's too late, but would helpful for people who have sufferd. I faced the same issue and I tried using IDbConnection is sort out from this pretty meaningless exception.
using (IDbConnection connection = new SnowflakeDbConnection()) { connection.ConnectionString = astrConnectionString; connection.Open(); obj = await connection.QueryAsync<T>(aStrSPName, adynamicParameters); connection.Close(); }
Now, you will get an exception with proper message if passed wrong schema/DB/Warehouse and credetials.