3

I have the following connection string:

<?xml version="1.0" encoding="utf-8"?>
  <connectionStrings>
    <add name="MyContext" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string='data source=SQLSERVERDB;initial catalog=TestDB_CodeFirst;user id=***;password=***;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

When I try to enable migrations I first get a warning:

Cannot determine a valid start-up project. Using project 'MyApp.Model' instead.
Your configuration file and working directory may not be set as expected.
Use the -StartUpProjectName parameter to set one explicitly.

Then I get this exception:

Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied.

Is the connection string wrong and why should I need ssdl if I'm using Code First?

NOTE

  • My context is in MyApp.Model project where my Migrations folder should be located.
  • I don't have connection strings in my main startup project because connection strings are retrieved from a second database and the user can select one of them when logging in to the application.
  • I have just one connection string shown above in my MyApp.Model project which points to my development database.

Also, my second question is:

If I use CF migrations, will all databases be migrated each time a user selects a different database for the first time?

EDIT

I changed the connection as mentioned below, and I get the following exception:

The item with identity 'table1' already exists in the metadata collection. Parameter name: item

It must be noted that I reverse-engineered an existing database. So I don't know what possibly went wrong!

I've also deleted the Migrations folder and checked the database but there is no migration_history table created.

2
  • Remove metadata=res://*; from your connection string I think, code first does not have/require metadata. Commented Nov 18, 2014 at 13:58
  • That's what I did first and it still complains: "Some required information is missing from the connection string. The 'metadata' keyword is always required." Commented Nov 18, 2014 at 14:01

1 Answer 1

7

You are trying to use a connectionString designed to work with Database First / Model First. You can tell because your providerName is System.Data.EntityClient instead of System.Data.SqlClient.

Your connection string should look like this:

<connectionStrings>
    <add name="MyContext" 
         connectionString="Data Source=SQLSERVERDB; Initial Catalog=TestDB_CodeFirst;user id=***;password=***;"
        providerName="System.Data.SqlClient" />
</connectionStrings

Although I would suggest using Integrated Security instead of a user/password. Just personal preference, though.

Sign up to request clarification or add additional context in comments.

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.