title: using entityFrameWork in windows service application gives the underlying providor failed to open error
body: <p>This is my service start code and my class. it is long but problem is just with database and entityFrameWork section please omit other lines. consider I just want to read a data from database:</p>
  
  <p>my service start code:</p>
  
  <pre><code>protected override void OnStart(string[] args)
      {
          System.Threading.Thread newThread = new System.Threading.Thread(new System.Threading.ThreadStart(ReadPolling.Read));
          newThread.Start();
      }
  </code></pre>
  
  <p>this is my ReadPolling.cs file:</p>
  
  <pre><code>public class ReadPolling
  {
      public static webtccUsersEntities db;
      public static void Read()
      {
          try
          {
              byte[] readBuffer = new byte[1024];
              while (true)
              {
                      writeToDb(readBuffer);
                      System.IO.File.WriteAllText("D:\\1.txt", "read-write");
              }
  
          }
          catch (Exception ex)
          {
              System.IO.File.WriteAllText("D:\\1.txt", ex.Message);
          }
  
      }
      public static void writeToDb(byte[] userId)
      {
          db = new webtccUsersEntities();
          string _userId="";foreach(byte item in userId)
          {
              if(item!=0 || item!=40)
              _userId += (39 - item).ToString();
          }
          _userId = "0009544023";
          Time time;
          if(db.Times.Where(i=&gt;i.userId==_userId).Count()&gt;0)//User has at least one time
          {
              time = db.Times.Where(i =&gt; i.userId == _userId).OrderBy(i =&gt; i.dayDate).OrderBy(i=&gt;i.inTime).Last();//last time
  
              if (time.dayDate == DateTime.Today)//today time
              { 
                  if(time.outTime==null)//wants an out for today
                  {
                      time.outTime = DateTime.Now.ToLocalTime();//an out for today
                      db.SaveChanges();
                  }
                  else//wants a new in/out for today
                  {
                      Time newTime = new Time();newTime = db.Times.Create();  newTime.userId = _userId; newTime.dayDate = DateTime.Now.Date; newTime.inTime = DateTime.Now.ToLocalTime();
                      db.Times.Add(newTime);db.SaveChanges();
                  }
              }
              else//not today time
              {
                  //new in for today
                  Time newTime = new Time();newTime = db.Times.Create();newTime.dayDate = DateTime.Today;newTime.inTime = DateTime.Now.ToLocalTime();newTime.userId = _userId;
                  db.Times.Add(newTime);db.SaveChanges();
              }
  
          }
          else//user first time
          {
              Time firstTime = new Time();
              firstTime = db.Times.Create();
              firstTime.userId = _userId;firstTime.dayDate = DateTime.Now.Date;firstTime.inTime = DateTime.Now.ToLocalTime();
              db.Times.Add(firstTime);db.SaveChanges();
          }
  
  
      }
  }
  </code></pre>
  
  <p>as you can see if an error occurs I write it to a file named "1.txt" in my drive "D:\". so when I start the service i open my text file and see the error "The underlying provider failed on Open.Login failed for user 'NT AUTHORITY\LOCAL SERVICE'.".
  what causes the problem?</p>