No matter what I do I get this error during run-time:
ExecuteReader requires an open and available Connection.
I have verified that this error is thrown with every SQL service access in my app, I've made sure that every time I access the DB, the connection is opened and then closed respectively.
Hare's an example of my DB class Code:
public void ConexionDB()
{
try
{
cnx = new SqlConnection();
cnx.ConnectionString = "Data Source=DESKTOP-GAHK8CT;Initial Catalog=WInventario;Integrated Security=True";
cnx.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
public void DELETE_Lineas(int ID)
{
try
{
ConexionDB();
SqlCommand cmd = new SqlCommand("spDELETE_Linea", cnx);
cmd.Connection = cnx;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ID_Linea", ID));
cmd.ExecuteNonQuery();
cnx.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
cnx.Close();
throw;
}
}
I have also made sure that the folder that contains has all the permissions with all the available users (Full access).
I'm not sure what else I can check to make it work.