私は私のタイトルに私にエラーを与える以下の行があります。NullReferenceExceptionしかしヌルがありません
dtDetail = SQLQuery.getRequestDetails(reqNo, vendorcode);
しかし、私はそれをテストし、dtDetail
はvendorCode
がnullでなく、私はアイデアのうち午前、reqNo
がnullではない、nullではありません。
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
私にエラーを与えた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年1月18日15:30:53303 [1] ERROR DrawingRequestEmail.Util [(ヌル)] - ReceiveEmail System.NullReferenceException:オブジェクト参照が設定されていませんオブジェクトのインスタンスに渡します。 (D:\ TFS \ SERVER \ Logistics \ Main \ MM \ DrawingRequest \ TFS \サーバ\物流\メイン\ MM \ DrawingRequest \ DrawingRequestEmail \ DrawingRequestEmail \ Util.cs:ライン123
Util.cs:ライン123
ret = email.ProcessEmailFromSubconSystem(oMessage);
Email.cs:ライン155
dtDetail = SQLQuery.getRequestDetails(reqNo, vendorcode);
例外を発生させるブロックのみを含めるようにしてください。 –
これらの 'throw ex;'ステートメントを 'throw'だけに置き換えてください。[あなたが報告しているスタックトレースを台無しにしています] http://stackoverflow.com/questions/730250/is-there-a-difference-between-throw-and-throw-ex)。もっと良いことに、何もしていないので、これらの 'try/catch/finally'ブロックをすべて削除してください。デフォルトの振る舞いは、例外を呼び出しメソッドまでスローすることです。 –
'getRequestDetails'メソッドにいくつかのブレークポイントを置き、実行中にステップポイントを進めます。そのメソッド内の何かが例外を引き起こしているに違いありません。 –