0
votes

I'm new to ef code first and have just used the reverse engineer code first to create a model of an existing database on Microsoft SQL Server 2008.

The problem I'm having is that even though I'm providing User ID and Password in the connection string, it's giving me an authentication error while complaining about my computer name as if I were using Integrated Security (which I'm not.)

The error I get is this:

Cannot open database \"edmTestDBContext\" requested by the login. The login failed.\r\nLogin failed for user 'jwelty-thinkpad\jwelty'.

My connectionString is this:

Data Source=srv-123;Initial Catalog=edmTestDB;Persist Security Info=True;User ID=user;Password=userpass;MultipleActiveResultSets=True

It seams to me like it's ignoring my User ID and using my machine name instead.

It's interesting that the connection string was auto generated by the Entity Framework tool and it worked for building the model but not for actually connecting the model back to the source database.

Any thoughts on what's going on?

I do have full permissions with my username/password as this is what I use with Sql Server Management Studio and that's also how I created the database in the first place.

I tried adding "Integrated Security=False;" and that was no help.

2

2 Answers

0
votes

It looks like EF isn't finding your connection string. Make sure that it is in the config file being used (you might need to copy it from the class library config to the application config) and that it either has the same name as the context class or that you provide DbContext with the name by calling the appropriate base constructor. For example:

public EdmTestDBContext()
 : base("name=MyConnectionStringName")
{
}
0
votes

There are some built-in conventions in EF Code-first such as using the name of derived context class from DbContext to find the related connection string in the .config file. So if your context class is named BlogContext, it will look for the following connectionString first:

<connectionStrings>
    <clear />
    <add
      name="BlogContext"
...