Oops, good evening,
I'm not sure what to do, but I'm not sure what to do, but I'm not sure what to do. explain why I thank :) Follow class and method the error is not con.disconnect ();:
public class Conexao:IDisposable
{
private static string stringConexao = ConfigurationManager.ConnectionStrings["stringConexao"].ConnectionString;
private SqlConnection con = new SqlConnection(stringConexao);
public void conectar()
{
if (con.State == System.Data.ConnectionState.Closed)
{
con.Open();
}
}
public void desconectar()
{
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
}
public SqlConnection getCon()
{
return con;
}
}
public int cadastrarAssociado (Associado assoc)
{
using(Conexao con = new Conexao())
{
using(SqlCommand comando = new SqlCommand(procCadastrar, con.getCon()))
{
comando.CommandType = System.Data.CommandType.StoredProcedure;
comando.Parameters.AddWithValue("@cpf", assoc.Cpf);
comando.Parameters.AddWithValue("@nome", assoc.Nome);
comando.Parameters.AddWithValue("@rg", assoc.Rg);
comando.Parameters.AddWithValue("@data_nasc", assoc.Nascimento.Date);
comando.Parameters.AddWithValue("@endereco", assoc.Endereco);
comando.Parameters.AddWithValue("@apto", assoc.Apto);
comando.Parameters.AddWithValue("@cidade", assoc.Cidade);
comando.Parameters.AddWithValue("@estado", assoc.Estado);
comando.Parameters.AddWithValue("@email", assoc.Email);
comando.Parameters.AddWithValue("@usuario", assoc.Login);
comando.Parameters.AddWithValue("@senha", assoc.Senha);
try
{
con.conectar();
return Convert.ToInt32(comando.ExecuteScalar());
con.desconectar();
}
catch (SqlException)
{
throw;
}
}
}
}