SQL Connection Exception errors

  • Thread starter Thread starter labjac
  • Start date Start date
L

labjac

Guest
Hallo

Hope all are well.

We running a program that continually pole a record in a database for enable flag. We creating numerous instances for the db connections class. Ever so often we get the error below from the exception handler, is there a way to resolve this or a better way to handle the Connection?

namespace WCS_Shared.Databases.SQL
{
public class SqlDbConnect
{
private SqlConnection _con;
public SqlCommand Cmd;
private SqlDataAdapter _da;
private DataTable _dt;

public SqlDbConnect()
{
_con = new SqlConnection(WCS_Shared.Databases.SQL.ConnectionString.GetConnectionString());

try
{
if (_con.State == ConnectionState.Open)
{
_con.Close();
}
_con.Open(); //This is line 25...
}
catch (Exception e)
{
LogFiles.ExceptionLogger.WriteException(e);
}
}

public void SqlQuery(string queryText)
{
Cmd = new SqlCommand(queryText, _con);
}

public DataTable QueryEx()
{
_da = new SqlDataAdapter(Cmd);
_dt = new DataTable();

try
{
_da.Fill(_dt);
}
catch (Exception e)
{
LogFiles.ExceptionLogger.WriteException(e);
}
return _dt;
}

public void NonQueryEx()
{
try
{
Cmd.ExecuteNonQuery();
}
catch (Exception e)
{
LogFiles.ExceptionLogger.WriteException(e);
}

}
}
}
1607414.jpg



labjac

Continue reading...
 
Back
Top