I have this line below giving me the error on my title.
dtDetail = SQLQuery.getRequestDetails(reqNo, vendorcode);
But I tested it, dtDetail
is not null, reqNo
is not null, vendorCode
is not null and I am out of idea.
logger.Debug("request#: " + reqNo);
logger.Debug("vendor code: " + vendorcode);
System.Data.DataTable dtDetail = new System.Data.DataTable();
if (dtDetail == null)
logger.Debug("dtDetail is null.");
if (SQLQuery.getRequestDetails(reqNo, vendorcode) == null)
logger.Debug("SQLQuery.getRequestDetails(reqNo, vendorcode) is null.");
dtDetail = SQLQuery.getRequestDetails(reqNo, vendorcode);
I tested SQLQuery.getRequestDetails(reqNo, vendorcode)
using the reqNo
and vendorCode
I get from logger.Debug
, there are no exception in there.
All testing is done on my local PC but connect to production database. Windows 7 Pro Service Pack 1.
The one that gave me error is production environment, a windows XP Pro 2002 Service Pack 3.
Below is SQLQuery class.
public static class SQLQuery
{
private static ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static DataTable getRequestDetails(string reqNo, string vendorcode)
{
DataSet ds = new DataSet();
string strSQL = string.Empty;
ATSSPCommon.SQLDB myDB = null;
string ret = string.Empty;
try
{
string strConnectionString = Config.DrawingConnString();
myDB = new ATSSPCommon.SQLDB(strConnectionString);
strSQL = " SELECT * FROM vw_drawing_req_status WHERE regno = '" + reqNo + "'" + " AND vendorcode = '" + vendorcode + "'";
ds = myDB.GetDataSet(strSQL);
}
catch (Exception ex)
{
logger.Error("request#: " + reqNo + ", vendor code: " + vendorcode, ex);
throw ex;
}
finally
{
}
if (ds.Tables[0].Rows.Count > 0)
return ds.Tables[0];
else
return null;
}
public static DataTable getRFQDetail(string reqNo, string vendorcode)
{
DataSet ds;
string strSQL = string.Empty;
ATSSPCommon.SQLDB myDB = null;
string ret = string.Empty;
try
{
string strConnectionString = Config.DrawingConnString();
myDB = new ATSSPCommon.SQLDB(strConnectionString);
strSQL = " SELECT * FROM t_RFQ_info WHERE regno = '" + reqNo + "'" +
"AND vendor_code = '" + vendorcode + "'";
ds = myDB.GetDataSet(strSQL);
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
if (ds.Tables[0].Rows.Count > 0)
return ds.Tables[0];
else
return null;
}
public static DataTable getVendorEmailAddress(string comp_code, string vendorcode)
{
DataSet ds;
string strSQL = string.Empty;
ATSSPCommon.SQLDB myDB = null;
string ret = string.Empty;
try
{
string strConnectionString = Config.DrawingConnString();
myDB = new ATSSPCommon.SQLDB(strConnectionString);
strSQL = " SELECT * FROM t_vendor_email WHERE comp_code = '" + comp_code + "'" +
"AND vendor = '" + vendorcode + "' AND status = 1";
ds = myDB.GetDataSet(strSQL);
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return ds.Tables[0];
}
public static string getModuleNumber(string reqNo)
{
DataSet ds;
string strSQL = string.Empty;
ATSSPCommon.SQLDB myDB = null;
string ret = string.Empty;
try
{
string strConnectionString = Config.DrawingConnString();
myDB = new ATSSPCommon.SQLDB(strConnectionString);
strSQL = " SELECT moduleno FROM subconjobQ WHERE regno = '" + reqNo + "'";
ret = myDB.GetOneValue(strSQL).ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return ret;
}
public static string getPlant(string reqNo)
{
DataSet ds;
string strSQL = string.Empty;
ATSSPCommon.SQLDB myDB = null;
string ret = string.Empty;
try
{
string strConnectionString = Config.DrawingConnString();
myDB = new ATSSPCommon.SQLDB(strConnectionString);
strSQL = " SELECT plant FROM subconjobQ WHERE regno = '" + reqNo + "'";
ret = myDB.GetOneValue(strSQL).ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return ret;
}
public static string getVendorCurrency(string plant, string vendorcode)
{
DataSet ds;
string strSQL = string.Empty;
ATSSPCommon.SQLDB myDB = null;
string ret = string.Empty;
try
{
string strConnectionString = Config.DrawingConnString();
myDB = new ATSSPCommon.SQLDB(strConnectionString);
strSQL = " SELECT currency FROM t_vendor_info WHERE plant = '" + plant + "'" +
"AND vendor = '" + vendorcode + "' AND status = 1";
ret = myDB.GetOneValue(strSQL).ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return ret;
}
public static void updateRFQTable(string regno, string vendor, string partno, string currency, double procCost, double rawCost, double treatCost, double unitPrice, string leadTime)
{
string strSQL = string.Empty;
ATSSPCommon.SQLDB myDB = null;
string ret = string.Empty;
try
{
string strConnectionString = Config.DrawingConnString();
myDB = new ATSSPCommon.SQLDB(strConnectionString);
strSQL = " UPDATE t_RFQ_info SET " +
"currency = '" + currency + "', " +
"process_cost = " + procCost + ", " +
"rawmat_cost = " + rawCost + ", " +
"treatment_cost = " + treatCost + ", " +
"unit_price = " + unitPrice + ", " +
"lead_time = '" + leadTime.Trim() + "', " +
"status = 1 " +
"WHERE Regno = '" + regno + "' AND " +
"vendor_code = '" + vendor + "' AND " +
"partno = '" + partno + "'";
myDB.ExecuteSQL(strSQL);
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
}
I even went and write a new function but it also give me the same error in the production environment.
class RFQHandler
{
public static DataTable GetRequestDetail(string requestNumber, string vendorCode)
{
string connectionString = Config.DrawingConnString();
SqlConnection sqlConnection = new SqlConnection(connectionString);
string commandText = "SELECT * FROM vw_drawing_req_status WHERE regno = @requestNumber AND vendorcode = @vendorCode";
SqlCommand sqlCommand = new SqlCommand(commandText, sqlConnection);
sqlCommand.Parameters.Add("@requestNumber", SqlDbType.Char, 12).Value = requestNumber;
sqlCommand.Parameters.Add("@vendorCode", SqlDbType.VarChar, 25).Value = vendorCode;
DataTable requestDetail = new DataTable();
using (sqlConnection)
using (sqlCommand)
{
sqlConnection.Open();
using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
{
requestDetail.Load(sqlDataReader);
}
}
return requestDetail;
}
}
Error message logged:
2017-01-18 15:30:53,303 [1] ERROR DrawingRequestEmail.Util [(null)] - ReceiveEmail System.NullReferenceException: Object reference not set to an instance of an object. at DrawingRequestEmail.Email.ProcessEmailFromSubconSystem(MailItem message) in D:\TFS\SERVER\Logistics\Main\MM\DrawingRequest\DrawingRequestEmail\DrawingRequestEmail\Email.cs:line 155 at DrawingRequestEmail.Util.ReceiveEmail() in D:\TFS\SERVER\Logistics\Main\MM\DrawingRequest\DrawingRequestEmail\DrawingRequestEmail\Util.cs:line 123
Util.cs:line 123
ret = email.ProcessEmailFromSubconSystem(oMessage);
Email.cs:line 155
dtDetail = SQLQuery.getRequestDetails(reqNo, vendorcode);