This starting to occcur today... I was searchiong for a solution, but I just can find it using in different scenarions like outside the azure functions or using a different client library. Anyway...
This is my client:
using System;
using endpoints3t.Models;
using System.Data.SqlClient;
namespace endpoints3t.DataAccess
{
internal class MssqlClient
{
public MsSqlServer Client;
private string thisEnv = Environment.GetEnvironmentVariable("ThisEnvironment");
public MssqlClient()
{
var str = Environment.GetEnvironmentVariable($"MsSql_{thisEnv}_ConnectionString");
SqlConnection c = new SqlConnection(str);
Client = new MsSqlServer()
{
Client = c
};
}
}
}
And this is a sample of a simple call:
public async Task<List<Something>> GetSomeData()
{
if (msSQL.Client.Client.State == System.Data.ConnectionState.Closed)
{
msSQL.Client.Client.Open();
}
using (SqlCommand cmd = new SqlCommand("ExecMyStoredProcedure", msSQL.Client.Client))
{
cmd.CommandType = CommandType.StoredProcedure;
var reader = await cmd.ExecuteReaderAsync();
while (reader.Read())
{
var item = new Something()
{
Id = Guid.Parse(reader["Id"].ToString())
};
result.Add(item);
}
}
return result;
}
According to documentation, System.Data.SqlClient controls the open/close of my connection and maybe for this reason I can't find much documentation about how to handle this situation. Any help ?