title: EF 4.1 code first causes weird (login) runtime errors
body: <p>I'm using EF 4.1 code first. Running into a very weird situation:
  Database does not exist, code is executed and as soon as the code wants to execute a query against the repository (using also repository pattern)  </p>
  
  <pre><code>MyRepsitory.Get(whereClause)
  </code></pre>
  
  <p>i'm getting this error:</p>
  
  <blockquote>
    <p>Cannot open database "MyDatabase"
    requested by the login. The login
    failed. Login failed for user 'sa'.</p>
  </blockquote>
  
  <p>OK! So i tried to find what it is caused by and did the following: set a break point at the line which caused the error and as soon as this line was hit, i issued from the debugging (watch) window another query against the repository</p>
  
  <pre><code>MyRepository.GetAll();
  </code></pre>
  
  <p>et voila  the database gets created. So i thought: why not trick the database (as a workaround) and issue this request against the repository? The result: i get the same error as soon as this gets executed in code!</p>
  
  <p>What am i doing wrong?
  This used to work like a charm!</p>
  
  <p><strong>EDIT</strong>
  This drives me mad!
  I isolated the model and some code (for the repository pattern) into a new project. Tried to execute the same code and it works in this new project. How is that possible?</p>
  
  <p>Looked in the logs of SQL Serv2008 Exp and i see the following errors/events:</p>
  
  <p>Starting up database 'MyDatabase'</p>
  
  <p>Setting database option SINGLE_USER to ON for database MyDatabase.</p>
  
  <p>Error: 18456, Severity: 14, State: 38.</p>
  
  <p>Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: ]</p>