Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct format for Running Entity Framework migrate.exe tool without a Web/App.config?

Tags:

We recently switched to Entity Framework data migrations and I am working on some build automation scripts for our MVC app. I can successfully run the migrations from our build server using the migrate.exe tool in 4.3 if I have a Web.config to point it at. The command looks something like:

ProjectName\packages\EntityFramework.4.3.1\tools\migrate.exe MyAssembly     /startupdirectory:ProjectName\bin\Debug      /startupconfigurationfile:ProjectName\Web.config      /verbose 

However, for various reasons I would like to avoid using the Web.config and just pass in the correct connection string at the time of the migration:

ProjectName\packages\EntityFramework.4.3.1\tools\migrate.exe MyAssembly     /startupdirectory:ProjectName\bin\Debug      /connectionString:"Data Source=awesomeserver;Initial Catalog=awesomedatabase;User Id=funkyuser;Password=crazypassword"      /verbose 

This does not work. Worse, it crashes migrate.exe with a NullReferenceException. The connection string is identical to the one we use in our Web.config.

Anyone encountered this before? Is my connection string format wrong? Bug?

like image 916
jslatts Avatar asked Mar 14 '12 15:03

jslatts


People also ask

What is ef6 exe?

The ef6.exe command line tool is found in the tools/ subfolder of the EntityFramework NuGet package. Because it is a standalone tool and NuGet packages are ZIP files, the executable can be extracted directly from the package in Windows by downloading the package, changing the extension from . nupkg to .

What is migration exe?

Code First Migrations can be used to update a database from inside visual studio, but can also be executed via the command line tool migrate.exe. This page will give a quick overview on how to use migrate.exe to execute migrations against a database.


1 Answers

Ok, we figured it out. When running without the Web.config, the connectionProviderName parameter must also be passed in:

ProjectName\packages\EntityFramework.4.3.1\tools\migrate.exe MyAssembly     /startupdirectory:ProjectName\bin\Debug      /connectionProviderName:"System.Data.SqlClient"     /connectionString:"Data Source=awesomeserver;Initial Catalog=awesomedatabase;User Id=funkyuser;Password=crazypassword"      /verbose 

I have confirmed that this works.

like image 95
jslatts Avatar answered Sep 19 '22 09:09

jslatts