我的代码检查数据库中的更改,然后通过Web服务将更新发送到客户端。
我让部分向客户端发送消息正常工作,因为调用检查数据库中的更改。现在我已经添加了部分检查数据库更改,我收到以下错误。
调试我的代码时,错误指向代码最底部的异常,所以我不知道错误来自哪里,也无法修复它。
任何建议都将非常感谢
SendInvUpdate.InvServices.UpdateRatePackagesRequest ur = new SendInvUpdate.InvServices.UpdateRatePackagesRequest();
SendInvUpdate.InvServices.UpdateRatePackagesOperationResponse or = new SendInvUpdate.InvServices.UpdateRatePackagesOperationResponse();
protected void Page_Load(object sender, EventArgs e)
{
try
{
string connStr = ConfigurationManager.ConnectionStrings["bb"].ConnectionString;
SqlConnection Con = new SqlConnection(connStr);
Con.Open();
SqlCommand cmd = new SqlCommand("invpush_PollForAvailableChanges", Con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter NewSysChangeVersionParam = new SqlParameter("@NewSysChangeVersion", SqlDbType.Int);
NewSysChangeVersionParam.Value = (object)NewSysChangeVersionParam ?? DBNull.Value;
NewSysChangeVersionParam.Direction = ParameterDirection.InputOutput;
NewSysChangeVersionParam.SqlDbType = SqlDbType.BigInt;
SqlDataReader sdr = cmd.ExecuteReader();
InventoryPushSubscriptionRecord rec = new InventoryPushSubscriptionRecord();
while (sdr.Read())
{
rec.InventoryPushSubId = sdr.GetInt32(0);
rec.CMName = sdr.GetString(1);
rec.NotifUrl = sdr.GetString(2);
rec.Options = sdr.GetString(3);
rec.LastSysChangeVersion = sdr.IsDBNull(4)?(long?)null:sdr.GetInt32(4);
}
if(!sdr.NextResult()) throw new System.Exception("Expected Result set 1 for InventoryChangeRecord");
InventoryChangeRecord inrec = new InventoryChangeRecord();
while (sdr.Read())
{
inrec.InventoryPushSubId= sdr.GetInt32(0);
inrec.SysChangeVersion=sdr.IsDBNull(1)?(long?)null:sdr.GetInt32(1);
inrec.InvDate=sdr.GetDateTime(2);
inrec.ResId=sdr.GetInt32(3);
inrec.RoomType=sdr.GetString(4);
inrec.InvCount=sdr.GetInt32(5);
inrec.ResName=sdr.GetString(6);
}
sdr.Close();
sdr.Dispose();
if (NewSysChangeVersionParam != null)
{
int ResId;
Int64 ResoId;
ResortId = inrec.ResId;
SqlDataAdapter sda = new SqlDataAdapter("Select BID,RId from BBTest.bbtest.tblResMapping where BId=@ResId",Con);
SqlParameter resId = new SqlParameter("@ResId", ResId);
sda.SelectCommand.Parameters.Add(resId);
DataSet ds = new DataSet();
sda.Fill(ds, "tblresmapping");
if (ds.Tables[0].Rows.Count > 0)
{
ResoId = Convert.ToInt32(ds.Tables[0].Rows[0]["ResonlineId"]);
}
if (ds.Tables[0].Rows.Count != 0)
{
Int64 RatePackageId;
SqlDataAdapter sqlda = new SqlDataAdapter("Select BId,BBRoom,ResRatePackageID from tblResRatePackages where BID =@ResortId", Con);
SqlParameter resI = new SqlParameter("@RId", resId);
sqlda.SelectCommand.Parameters.Add(resI);
DataSet dt = new DataSet();
sqlda.Fill(dt, "tblResRatePackages");
if (dt.Tables[0].Rows.Count > 0)
{
RatePackageId = Convert.ToInt64(dt.Tables[0].Rows[0]["ResRatePackageID"]);
Int64 HID = ResId;
Int64 HRID = RatePackageId;
SendInvUpdate.InvServices.UpdateRatePackagesRequest request = new SendInvUpdate.InvServices.UpdateRatePackagesRequest();
request.HotelId = account.HotelId;
int avail = inrec.InvCount;
DateTime frodte = inrec.InvDate;
int NoofRatePackages = 3;
UpdateRatePackageRequest[] RatePackages = new UpdateRatePackageRequest[NoofRatePackages];
string res;
request.RatePackages = new UpdateRatePackageRequest[NoofRatePackages];
request.RatePackages = RatePackages;
for (int i = 0; i < NoofRatePackages; i++)
{
UpdateRatePackageRequest rp = new UpdateRatePackageRequest();
request.RatePackages[i] = rp;
rp.RatePackageId = HRID;
rp.Rates = new RateDetails[NoofRatePackages];
for (int j = 0; j < NoofRatePackages; j++)
{
RateDetails rd = new RateDetails();
rp.Rates[j] = rd;
rd.Availability = avail;
rd.AvailabilityApplicationType = SendInvUpdate.InvServices.AvailabilityApplicationType.SET;
rd.FromDate = frodte;
// rd.ToDate = todte;
}
}
SendInvUpdate.InvServices.InventoryServiceClient isc = new SendInvUpdate.InvServices.InventoryServiceClient();
or = isc.UpdateRatePackages(request);
res = or.Results.ToString();
}
}
}
}
catch (Exception ex)
{
throw (ex);
}
}
}
}
答案 0 :(得分:3)
你正在隐藏真正的异常堆栈跟踪,捕获异常并像你一样再次抛出它;
try {
...
}
catch(Exception ex) // catch all exceptions
{
throw ex; // throw the same exception, removing the old stack trace
}
您应该删除整个try / catch,或者更改为;
try {
...
}
catch(Exception ex) // catch all exceptions
{
throw; // throw the last caught exception, keeping the stack trace
}
您将突然看到原始异常的确切位置。我相信你会马上发现你的错误。
答案 1 :(得分:1)
要尝试的一件事:在try-catch块的开头设置一个断点,在connStr =行上,逐行逐步执行代码,继续进行方法调用。通过这种方式,您可以快速跟踪代码的哪一部分引发错误,然后回到该点以查找特定问题。 (您还可以在重新抛出之前阅读原始异常和innerexception消息。)
鉴于你的问题的标题,所以假设你所遇到的错误是一个转换异常,我要检查的第一个地方就是你的数据库数据检索代码。例如,您正在使用sdr.GetInt32(0),如果无法将列0转换为整数,则会抛出此类错误。
希望这会有所帮助。如果您能够追踪更多信息,请发布,我们会看看是否可以提供更具体的建议。
答案 2 :(得分:1)
在我的情况下,收到此错误消息后,Oracle最终返回了一个无理数。
我的代码抛出&#34;指定演员表无效&#34; adapter.Fill(ds);
的异常.NET没有使用我一直使用的代码正确解释返回的数字。添加行adapter.ReturnProviderSpecificTypes = true;
使.NET可以解释数字,四舍五入到第N个小数(由于某种原因,最后一个数字从3到4舍入......):2.25000000000000333333333333333333333334
private static DataSet dataset_test(string sql)
{
DataSet ds = new DataSet();
using (OracleConnection objConn = new OracleConnection(connectionstring))
{
OracleCommand objCmd = new OracleCommand();
objCmd.Connection = objConn;
objCmd.CommandText = sql;
objCmd.CommandType = CommandType.Text;
try
{
objConn.Open();
OracleDataAdapter adapter = new OracleDataAdapter(objCmd);
adapter.ReturnProviderSpecificTypes = true;
adapter.Fill(ds);
}
catch (Exception)
{
throw;
}
objConn.Close();
return ds;
}
}