title: Is my DB connection closed? (Linq to Sql)
body: <p>I'm using Linq to SQL and read in a blog post about closing database connections as soon as possible. As an example, they showed a variable being converted to a list (using .ToList()) instead of actually returning the Linq query. I have the below code:</p>
  
  <pre><code> public static bool HasPassword(string userId)
   {
  
      ProjDataContext db = new ProjDataContext();
  
      bool hasPassword = (from p in db.tblSpecUser
                                      where p.UserID == userId
                                      select p.HasPassword).FirstOrDefault();
  
  
      return hasPassword;
   }
  </code></pre>
  
  <p>Is that query fine? Or will the database connection remain open for longer than necessary?</p>
  
  <p>Thank you for any advice</p>