0
I have a DataReader
on my website to read the data that the bank brings. There when two people enter different computers, and even different browsers, opens a connection, but at the time I will read some data VS returns me an error
There is already an open Datareader associated with this Command that must be closed first
Would you have something that could change so that several people could access at the same time? Close Datareader?
public static List<dMovimentoUser> listar_lancamentos(string conexao)
{
List<dMovimentoUser> carrinho = new List<dMovimentoUser>();
Dados objDados = new Dados();
SqlCommand command = new SqlCommand("usp_lancamentos_internos_listar", objDados.abreConexao());
command.Parameters.AddWithValue("@conexao", conexao);
command.CommandType = CommandType.StoredProcedure;
SqlDataReader reader;
reader = command.ExecuteReader();
objDados.abreConexao();
try
{
while (reader.Read())
{
dMovimentoUser ct = new dMovimentoUser();
ct.codigo = reader["código"].ToString();
ct.descricao = reader["produto"].ToString();
ct.data = reader["data"].ToString();
ct.hora = reader["hora"].ToString();
ct.operacao = reader["operacao"].ToString();
ct.qtd = float.Parse(reader["quantidade"].ToString());
ct.historico = reader["historico"].ToString();
carrinho.Add(ct);
}
return carrinho;
}
catch (Exception ex)
{
throw new Exception("Erro encontrado: " + ex.Message);
}
finally
{
reader.Close();
objDados.fechaConexao();
}
}
you are using a static Sqlconnection inside your
Dados
?– Bruno Piovan
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero