Windows 服务未连接到数据库
本文关键字:数据库 连接 服务 Windows | 更新日期: 2023-09-27 18:32:34
我有一个Windows服务。它每 18 秒连接并检查一次我的数据库,然后再向外部客户端发送 SOAP 消息。我已经在我的计算机上成功安装了该服务,但它没有做任何特别的事情,也没有用任何错误填充我的服务器日志。
如何找出我出错的地方?
更新
protected override void OnStart(string[] args)
{
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Interval = 15000;
timer.Enabled = true;
timer.Start();
eventLog1.WriteEntry("Windows Service 3 Started");
}
protected override void OnStop()
{
eventLog1.WriteEntry("Windows Service 3 Stopped");
}
我的RunAPP()
是通过存储过程连接到数据库的地方。
对我的问题有任何见解都会很棒!
private void RunApp()
{
p.Start();
string connStr = ConfigurationManager.ConnectionStrings["bbsConnectionString"].ConnectionString;
try
{
SqlConnection Con = new SqlConnection(connStr);
Con.Open();
SqlCommand cmd = new SqlCommand("AvailableChanges", Con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter NewSysChangeVersionParam = new SqlParameter("@NewSysChangeVersion", SqlDbType.Int);
NewSysChangeVersion.Value = (object)NewSysChangeVersion ?? DBNull.Value;
NewSysChangeVersion.Direction = ParameterDirection.InputOutput;
NewSysChangeVersion.SqlDbType = SqlDbType.BigInt;
SqlDataReader sdr = cmd.ExecuteReader();
int sdrreader = sdr.FieldCount;
InventoryPushSubscriptionRecord rec = new InventoryPushSubscriptionRecord();
while (sdr.Read())
{
inrec.InventoryPushSubscriptionId = sdr.GetInt32(0);
inrec.SysChangeVersion = sdr.IsDBNull(1) ? (long?)null : sdr.GetInt64(1);
inrec.InvDate = sdr.GetDateTime(2);
inrec.ResortId = sdr.GetInt32(3);
inrec.RoomType = sdr.GetString(4);
inrec.InvCount = sdr.GetInt32(5);
inrec.ResortName = sdr.GetString(6);
Int64 NewSysChangeVersion;
NewSysChangeVersion = Convert.ToInt64(rec.LastSysChangeVersion);
int ResortId;
ResortId = inrec.ResortId;
string RoomType;
RoomType = inrec.RoomType;
int avail = inrec.InvCount;
DateTime frodte = inrec.InvDate;
DateTime todte = inrec.InvDate;
int NoofRatePackages = sdrreader;
Int32 InventoryPushSubscriptionId;
InventoryPushSubscriptionId = inrec.InventoryPushSubscriptionId;
Int64 NewLastSysChangeVersion;
NewLastSysChangeVersion = Convert.ToInt64(inrec.SysChangeVersion);
if (NewSysChangeVersion != null)
{
sendUpdate(NewSysChangeVersion, ResortId, RoomType, avail, frodte, todte, NoofRatePackages, InventoryPushSubscriptionId, NewLastSysChangeVersion);
}
}
// sdr.Close();
// sdr.Dispose();
}
catch (Exception ex)
{
更新 eventLog1.WriteEntry("exception"); 扔; } }
按照建议编辑了我的异常。
捕获(例外,例如) {
eventLog1.WriteEntry(ex.Message);
eventLog1.WriteEntry(ex.StackTrace);
throw;
}