I keep getting the error 'Use of unassigned local variable' in this code, which I have used before and it works fine :
SqlTransaction Trans1, Trans2;
SqlConnection objConnectionDeactivateInvisilinkLNX, objConnectionDeactivateInvisilinkSQLSRVXwireless;
SqlCommand objCommandDeactivateInvisilinkLNX, objCommandDeactivateInvisilinkSQLSRVXwireless;
try
{
//Trans 1 - COM4S_CARDS
objConnectionDeactivateInvisilinkLNX = new SqlConnection(ConfigurationSettings.AppSettings["strConnectLNXTest"]);
objConnectionDeactivateInvisilinkLNX.Open();
objCommandDeactivateInvisilinkLNX = objConnectionDeactivateInvisilinkLNX.CreateCommand();
Trans1 = objConnectionDeactivateInvisilinkLNX.BeginTransaction(IsolationLevel.ReadCommitted);
objCommandDeactivateInvisilinkLNX.Connection = objConnectionDeactivateInvisilinkLNX;
objCommandDeactivateInvisilinkLNX.Transaction = Trans1;
//Trans 2 - NUM_TABLE
objConnectionDeactivateInvisilinkSQLSRVXwireless = new SqlConnection(ConfigurationSettings.AppSettings["strConnectSQLSRVXwirelessTest"]);
objConnectionDeactivateInvisilinkSQLSRVXwireless.Open();
objCommandDeactivateInvisilinkSQLSRVXwireless = objConnectionDeactivateInvisilinkSQLSRVXwireless.CreateCommand();
Trans2 = objConnectionDeactivateInvisilinkSQLSRVXwireless.BeginTransaction(IsolationLevel.ReadCommitted);
objCommandDeactivateInvisilinkSQLSRVXwireless.Connection = objConnectionDeactivateInvisilinkSQLSRVXwireless;
objCommandDeactivateInvisilinkSQLSRVXwireless.Transaction = Trans2;
}
catch
{
lblDeactivateInvisilinkResult.Text = "Could Not Connect To Database - please try again later";
}
try
{
//1 - COM4S_CARDS
string strUpdateCOM4SCards;
strUpdateCOM4SCards = "UPDATE COM4S_CARDS ";
strUpdateCOM4SCards += "SET STATE = 'N', ALLOW_TOGGLE = 0, SECONDARY_OLI = NULL, G_BIT = 0 ";
strUpdateCOM4SCards += "WHERE SERIAL = " + Convert.ToInt32(ViewState["Serial"]);
objCommandDeactivateInvisilinkLNX.CommandText = strUpdateCOM4SCards;
objCommandDeactivateInvisilinkLNX.ExecuteNonQuery();
//2 - NUM_TABLE
string strUpdateNumTable, strCLI;
strCLI = Convert.ToString("07059" + ViewState["Serial"]);
strUpdateNumTable = "DELETE FROM NUM_TABLE ";
strUpdateNumTable += "WHERE CLI = '" + strCLI + "'";
objCommandDeactivateInvisilinkSQLSRVXwireless.CommandText = strUpdateNumTable;
objCommandDeactivateInvisilinkSQLSRVXwireless.ExecuteNonQuery();
Trans1.Commit();
Trans2.Commit();
objConnectionDeactivateInvisilinkLNX.Close();
objConnectionDeactivateInvisilinkSQLSRVXwireless.Close();
lblDeactivateInvisilinkResult.Text = "Number Successfully Activated";
}
catch
{
Trans1.Rollback();
Trans2.Rollback();
objConnectionDeactivateInvisilinkLNX.Close();
objConnectionDeactivateInvisilinkSQLSRVXwireless.Close();
lblDeactivateInvisilinkResult.Text = "Database Error - please try again later";
}
Can anybody help me out with this?
Thanks,
lfc77
SqlTransaction Trans1, Trans2;
SqlConnection objConnectionDeactivateInvisilinkLNX, objConnectionDeactivateInvisilinkSQLSRVXwireless;
SqlCommand objCommandDeactivateInvisilinkLNX, objCommandDeactivateInvisilinkSQLSRVXwireless;
try
{
//Trans 1 - COM4S_CARDS
objConnectionDeactivateInvisilinkLNX = new SqlConnection(ConfigurationSettings.AppSettings["strConnectLNXTest"]);
objConnectionDeactivateInvisilinkLNX.Open();
objCommandDeactivateInvisilinkLNX = objConnectionDeactivateInvisilinkLNX.CreateCommand();
Trans1 = objConnectionDeactivateInvisilinkLNX.BeginTransaction(IsolationLevel.ReadCommitted);
objCommandDeactivateInvisilinkLNX.Connection = objConnectionDeactivateInvisilinkLNX;
objCommandDeactivateInvisilinkLNX.Transaction = Trans1;
//Trans 2 - NUM_TABLE
objConnectionDeactivateInvisilinkSQLSRVXwireless = new SqlConnection(ConfigurationSettings.AppSettings["strConnectSQLSRVXwirelessTest"]);
objConnectionDeactivateInvisilinkSQLSRVXwireless.Open();
objCommandDeactivateInvisilinkSQLSRVXwireless = objConnectionDeactivateInvisilinkSQLSRVXwireless.CreateCommand();
Trans2 = objConnectionDeactivateInvisilinkSQLSRVXwireless.BeginTransaction(IsolationLevel.ReadCommitted);
objCommandDeactivateInvisilinkSQLSRVXwireless.Connection = objConnectionDeactivateInvisilinkSQLSRVXwireless;
objCommandDeactivateInvisilinkSQLSRVXwireless.Transaction = Trans2;
}
catch
{
lblDeactivateInvisilinkResult.Text = "Could Not Connect To Database - please try again later";
}
try
{
//1 - COM4S_CARDS
string strUpdateCOM4SCards;
strUpdateCOM4SCards = "UPDATE COM4S_CARDS ";
strUpdateCOM4SCards += "SET STATE = 'N', ALLOW_TOGGLE = 0, SECONDARY_OLI = NULL, G_BIT = 0 ";
strUpdateCOM4SCards += "WHERE SERIAL = " + Convert.ToInt32(ViewState["Serial"]);
objCommandDeactivateInvisilinkLNX.CommandText = strUpdateCOM4SCards;
objCommandDeactivateInvisilinkLNX.ExecuteNonQuery();
//2 - NUM_TABLE
string strUpdateNumTable, strCLI;
strCLI = Convert.ToString("07059" + ViewState["Serial"]);
strUpdateNumTable = "DELETE FROM NUM_TABLE ";
strUpdateNumTable += "WHERE CLI = '" + strCLI + "'";
objCommandDeactivateInvisilinkSQLSRVXwireless.CommandText = strUpdateNumTable;
objCommandDeactivateInvisilinkSQLSRVXwireless.ExecuteNonQuery();
Trans1.Commit();
Trans2.Commit();
objConnectionDeactivateInvisilinkLNX.Close();
objConnectionDeactivateInvisilinkSQLSRVXwireless.Close();
lblDeactivateInvisilinkResult.Text = "Number Successfully Activated";
}
catch
{
Trans1.Rollback();
Trans2.Rollback();
objConnectionDeactivateInvisilinkLNX.Close();
objConnectionDeactivateInvisilinkSQLSRVXwireless.Close();
lblDeactivateInvisilinkResult.Text = "Database Error - please try again later";
}
Can anybody help me out with this?
Thanks,
lfc77