First Azure EF Migration Initializer

I just messed around with Azure and I can't get Db to work. I follow what he says here: https://www.windowsazure.com/en-us/develop/net/tutorials/web-site-with-sql-database/ and I updated my web.config to have following:

<entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <contexts> <context type="DownloadThis.Models.DownloadThisDb, DownloadThisDb"> <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion"> <parameters> <parameter value="DownloadThisDb_DatabasePublish" /> </parameters> </databaseInitializer> </context> </contexts> </entityFramework> 

As the example shows, but I keep getting this error:

The format of the initialization string does not meet the specification starting at index 0.

I checked triple my connectionString, so these are not all ideas?

+4
source share
3 answers

I think your type string is missing . :

 <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion"> 

The red box above the code makes it difficult to read ...

If you fix this, post a comment and I’ll prepare a sample to match yours and see if I can make it work ...

[UPDATED 2012-08-15]

OK. I think I know what is going on here ... You mentioned "I updated my web.config to have this:" and showed your XML. When I looked through the tutorial, I didn't have to inject ANY additional XML into my web.config . During the publishing process, XML was automatically added for me using the Visual Studio deployment process, and it all “just worked.”

Here is your solution:

Revert to the original web.config without these updates and republish.

For reference, here are the <entityFramework> sections from my two web.config files, first from my project, the second from my hosted service (I got this by connecting to a working site via FTP and downloading it). The VS project is called 11964172 after the SO record number for this message:

local web.config options

  <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> 

deployed web.config options

  <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> <contexts> <context type="_11963331.Models.ToDoDb, 11963331"> <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[_11963331.Models.ToDoDb, 11963331], [_11963331.Migrations.Configuration, 11963331]], EntityFramework, PublicKeyToken=b77a5c561934e089"> <parameters> <parameter value="_11963331.Models.ToDoDb_DatabasePublish" /> </parameters> </databaseInitializer> </context> </contexts> </entityFramework> 

I think this explains why they took a snapshot of the changes to the web.config instead of actually providing the code for input :-)

+1
source

Assuming you publish the VS2012 Publishing Wizard, I ran into the same issue. If you decide that the publication wizard will allow the first migration migrations instead of manually connecting them to your code, you need to specify the connection string in the publication settings. Your normal connection string is not used to start the migration, this new connection string is used only for this purpose. This is good because you can specify an account with elevated privileges to perform your migrations, however your application will not work in this user context. The problem is that the wizard does not require special indication of this connection string. If you do not, you will get a migration connection string of zero, and you will spend a lot of time trying to figure out what is wrong with your normal connection strings.

Publish Web Application Settings

Say your context class is called FooContext. By convention, you will have a connection string in your web.config named FooContext. When you enable code migration using this wizard, the wizard will create a second connection string named FooContext_DatabasePublish, which will only be used to start the first code migrations.

This MSDN blog post explains this process in detail.

+8
source

See this question . If you leave the deployment connection string as “Remote connection string” and check the box “Run the first migration start”, you will get this exception, because the DownloadThisDb_DatabasePublish migration connection string will not be defined properly. Either specify the actual connection string instead of leaving the connection string field blank in the deployment wizard, or specify the connection string named DownloadThisDb_DatabasePublish in your Azure site configuration.

0
source

All Articles