EF 4.1 code first causes weird (login) runtime errors

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)

MyRepsitory.Get(whereClause)

i'm getting this error:

Cannot open database "MyDatabase" requested by the login. The login failed. Login failed for user 'sa'.

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

MyRepository.GetAll();

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!

What am i doing wrong? This used to work like a charm!

EDIT 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?

Looked in the logs of SQL Serv2008 Exp and i see the following errors/events:

Starting up database 'MyDatabase'

Setting database option SINGLE_USER to ON for database MyDatabase.

Error: 18456, Severity: 14, State: 38.

Login failed for user 'sa'. Reason: Failed to open the explicitly specified database. [CLIENT: ]

7
задан Savvas Sopiadis 5 May 2011 в 22:55
поделиться