Estou trabalhando em um projeto de criações de bots para automação de tarefas e estou enfrentando alguns problemas relacionados a timeout de conexao.
O banco de dados e SQL Server, toda a manipulação do banco está sendo feita a partir de procedures executadas por SQL Command, estou usando Using nas minhas conexoes e mesmo assim está dando timeout de conexao
Quando eu executo algumas vezes funciona porém lá na centésima vez ele estoura esta exception.
Abaixo está o método que eu estou executando;
//ADICIONA TASK
public void AddTask(string task, string owner, string args)
{
LogIntegration.AddLog("Iniciando inserção de tarefa");
//PROC DE EXECUCAO
string proc = "PROC_INSERT_TASK_TASK";
//CRIANDO CONEXAO
LogIntegration.AddLog(args);
try
{
using (SqlConnection conexao = SQLConnectionFactory.getConnection())
{
//ABRINDO CONEXAO
conexao.Open();
//CRIANDO COMANDO
SqlCommand comando = new SqlCommand(proc, conexao);
//SETANDO COMMANDO TYPE
comando.CommandType = System.Data.CommandType.StoredProcedure;
//SETANDO PARAMETROS
comando.Parameters.AddWithValue("@TATY_TX_NAME", task);
comando.Parameters.AddWithValue("@USER_TX_EMAIL", owner);
comando.Parameters.AddWithValue("@TASK_TX_ARGS", args);
comando.CommandTimeout = 120;
//EXECUTANDO COMANDO
comando.ExecuteNonQuery();
LogIntegration.AddLog("Inserida com sucesso!");
}
}
catch (SqlException e)
{
LogIntegration.AddLog("Erro ao inserir tarefa : "+e.Message);
}
}
ERRO MESAGE:
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached
STACKTRACE:
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.Open() at RecepcaoBOT.DAO.RecepcaoDAO.AddTask(String task, String owner, String args) in R:\Informatica\Guilherme Maciel\PROJETOS\ETL BOT\CODIGO FONTE\ETL2\RecepcaoBOT\DAO\RecepcaoDAO.cs:line 136 at RecepcaoBOT.Negocio.Importador.OperatorFileImport.LoteImport(FileAttachment arquivo, ComandoEmail comando, EmailMessage email) in R:\Informatica\Guilherme Maciel\PROJETOS\ETL BOT\CODIGO FONTE\ETL2\RecepcaoBOT\Negocio\Importador\OperatorFileImport.cs:line 171 at RecepcaoBOT.Negocio.Importador.OperatorFileImport.BasicFilterImport(Int32 tarefa, ComandoEmail comando, EmailMessage email) in R:\Informatica\Guilherme Maciel\PROJETOS\ETL BOT\CODIGO FONTE\ETL2\RecepcaoBOT\Negocio\Importador\OperatorFileImport.cs:line 49 at RecepcaoBOT.Negocio.Importador.Importar.ImportarArquivo(Int32 tarefa, ComandoEmail comando, EmailMessage email) in R:\Informatica\Guilherme Maciel\PROJETOS\ETL BOT\CODIGO FONTE\ETL2\RecepcaoBOT\Negocio\Importador\Importar.cs:line 41 at RecepcaoBOT.Negocio.Atribuidor.AtribuirEmail(Int32 tarefa, ComandoEmail comando, EmailMessage email, String bodyComp) in R:\Informatica\Guilherme Maciel\PROJETOS\ETL BOT\CODIGO FONTE\ETL2\RecepcaoBOT\Negocio\Atribuidor.cs:line 70 at RecepcaoBOT.CORE.RecepcaoBot.Main(String[] args) in R:\Informatica\Guilherme Maciel\PROJETOS\ETL BOT\CODIGO FONTE\ETL2\RecepcaoBOT\CORE\RecepcaoBot.cs:line 79