0
我有一个Windows服务。它每隔18秒就会连接并检查我的数据库,然后向外部客户端发送soap消息。 我已经成功在我的电脑上安装了服务,但它没有做任何特别的事情,也没有填写任何错误的服务器日志。Windows服务未连接到数据库
如何找出我出错的地方?
更新
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( “异常”);抛出; 扔; } }
我怀疑摆脱,你必须分享RunApp'的'内容的社区任何见解,因为这是在失败发生。 “RunApp”中的一个例外可能会导致您的日志不被写入... – 2012-04-26 22:36:28
那么,您是否在事件日志中获得了这两条消息?如果是的话,你发布了错误的代码。如果没有,您从未开始使用该服务,或者您发布了错误的代码。 – 2012-04-26 22:40:36
好吧,但我上次把我的代码放在我的一个问题上,我被告知它太长了,没有人想滚动它....我将编辑我的问题,包括代码,@Tony Hopkinson我的事件日志显示“Windows服务3已经启动,运行应用程序”,之后没有任何其他。 – user1270384 2012-04-26 22:55:18