【发布时间】:2017-06-02 06:33:44
【问题描述】:
我在下面的这一行给出了我标题上的错误。
dtDetail = SQLQuery.getRequestDetails(reqNo, vendorcode);
但我测试了,dtDetail 不为空,reqNo 不为空,vendorCode 不为空,我不知道。
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);
我使用从logger.Debug 得到的reqNo 和vendorCode 测试了SQLQuery.getRequestDetails(reqNo, vendorcode),那里没有异常。
所有测试都在我的本地 PC 上完成,但连接到生产数据库。 Windows 7 专业版服务包 1。
给我错误的是生产环境,Windows XP Pro 2002 Service Pack 3。
下面是 SQLQuery 类。
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
{
}
}
}
我什至去写了一个新函数,但它在生产环境中也给了我同样的错误。
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;
}
}
记录的错误消息:
2017-01-18 15:30:53,303 [1] 错误 DrawingRequestEmail.Util [(null)] - ReceiveEmail System.NullReferenceException:对象引用未设置为对象的实例。 在 D:\TFS\SERVER\Logistics\Main\MM\DrawingRequest\DrawingRequestEmail\DrawingRequestEmail\Email.cs:line 155 中的 DrawingRequestEmail.Email.ProcessEmailFromSubconSystem(MailItem 消息) 在 D:\TFS\SERVER\Logistics\Main\MM\DrawingRequest\DrawingRequestEmail\DrawingRequestEmail\Util.cs:line 123 中的 DrawingRequestEmail.Util.ReceiveEmail() 处
Util.cs:第 123 行
ret = email.ProcessEmailFromSubconSystem(oMessage);
Email.cs:第 155 行
dtDetail = SQLQuery.getRequestDetails(reqNo, vendorcode);
【问题讨论】:
-
能否请您删除不相关的代码,并仅包含引发异常的块
-
@GrantWinney 我测试了
getRequestDetails,没有错误。 -
您的问题缺少信息;它在哪个环境中返回 NullReferenceException?提供两种环境的详细信息,一种会产生错误,另一种不会产生错误。
-
在您编写的新函数中,您能否准确检查在哪一行引发了异常?您能否提供异常的详细信息?
-
@EmersonCardoso 我无法在生产环境中设置断点。我在编辑中更新了异常。
标签: c# console-application windows-xp .net-2.0