Regarding the snowflake .NET connector: https://github.com/snowflakedb/snowflake-connector-net, I can find nothing in the documentation or source code to suggest that connection pooling is supported, and because the connection itself is backed by HttpClient, and we know that HttpClient should be reused rather than created/disposed constantly, what's the best way to use the snowflake .NET connector when you'll be making many queries across threads?
Note: I'm not planning on changing any properties of the connection once it's created (schema, database, etc.).
For example:
// application startup registers this provider as a singleton
public class SnowflakeConnectionProvider : IDisposable
{
private IDbConnection _conn;
public SnowflakeConnectionProvider()
{
_conn = new SnowflakeDbConnection();
_conn.ConnectionString = "connectionString";
_conn.Open();
}
public IDbConnection conn { get => _conn; }
public Dispose() => _conn.Close();
}
Now, is it safe for multiple threads to share the one SnowflakeDbConnection like so:
public class Worker
{
public Worker(SnowflakeConnectionProvider provider)
{
IDbConnection conn = provider.conn;
IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from t";
IDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
Console.WriteLine(reader.GetString(0));
}
}
}