33

I am getting this error when using Entity Framework 4.1 code first. I can not find any sources of what exactly to use.

Unable to load the specified metadata resource.

<add name="DataContext" connectionString="metadata=res://*/GrassrootsHoopsDataContext.csdl|res://*/GrassrootsHoopsDataContext.ssdl|res://*/GrassrootsHoopsDataContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=myserver.com;Initial Catalog=MyDataBase;Persist Security Info=True;User ID=username;Password=password&quot;" providerName="System.Data.EntityClient" />
1
  • 1
    Btw I think this type of connectionstrings with "metadata.." is only for model first and database first Commented Apr 9, 2014 at 13:24

2 Answers 2

69

For EF Code First you can use ordinary connection string if you are using SQL Server.

<add name="DataContext" connectionString="Data Source=myserver.com;Initial Catalog=MyDataBase;Persist Security Info=True;User ID=username;Password=password"  providerName="System.Data.SqlClient" />
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, finally a correct answer. I only wasted the better part of the day trying the find or generate the metadata files ...
Thank you. I had the same issue, but I also had to correct the ConnectionString I was dynamically building and passing into the DbContext via the controller's constructor.
1

If you are creating dynamic connection string for Code First Entity Framework than you can do using only Sql Connection String Builder as given below.

 public static string  DynamicConnectionString(SqlConnectionStringBuilder builder)
 {
    SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
    builder.DataSource = "ServerName";
    builder.InitialCatalog = "DatabaseName";
    builder.UserID = "UserId";
    builder.Password = "Password";
    builder.MultipleActiveResultSets = true;
    builder.PersistSecurityInfo = true;    
    return builder.ConnectionString.ToString();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.