2012-04-26 128 views
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( 「異常」);拋出; 扔; } }

+1

我懷疑擺脫,你必須分享RunApp'的'內容的社區任何見解,因爲這是在失敗發生。 「RunApp」中的一個例外可能會導致您的日誌不被寫入... – 2012-04-26 22:36:28

+0

那麼,您是否在事件日誌中獲得了這兩條消息?如果是的話,你發佈了錯誤的代碼。如果沒有,您從未開始使用該服務,或者您發佈了錯誤的代碼。 – 2012-04-26 22:40:36

+0

好吧,但我上次把我的代碼放在我的一個問題上,我被告知它太長了,沒有人想滾動它....我將編輯我的問題,包括代碼,@Tony Hopkinson我的事件日誌顯示「Windows服務3已經啓動,運行應用程序」,之後沒有任何其他。 – user1270384 2012-04-26 22:55:18

回答

0

按照建議編輯我的例外。

趕上(例外前){

  eventLog1.WriteEntry(ex.Message); 
      eventLog1.WriteEntry(ex.StackTrace); 
      throw; 

     } 
相關問題