1

I am trying to generate a new migration script in NuGet. After typing add-migration Initial The following response is generated. NOTE: My project still compiles and runs with no errors...

    PM> add-migration Initial
System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
   at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
   at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
   at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
   at MySql.Data.MySqlClient.MySqlConnectionStringBuilder..ctor(String connStr)
   at MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value)
   at MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString)
   at MySql.Data.Entity.MySqlConnectionFactory.CreateConnection(String connectionString)
   at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
   at System.Data.Entity.Internal.LazyInternalConnection.get_Connection()
   at System.Data.Entity.Internal.LazyInternalContext.get_Connection()
   at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo, Func`1 resolver)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Format of the initialization string does not conform to specification starting at index 0.

I have been following the guide at this question to establish a conenction to my Google Cloud SQL server: Dynamic MySQL database connection for Entity Framework 6

My connection string:

    <add name="CCGamesGCloud.EntityFramework.Context" connectionString="Server=******;Database=*****;Uid=****;Pwd=*********"
  providerName="MySql.Data.MySqlClient" />

My EF string:

<entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>

Context Class:

public class Context : DbContext
{
    public Context() : base("CCGamesGCloud.EntityFramework.Context")
    {

    }

    public virtual DbSet<Developer> Developers { get; set; }
    //... etc. etc... for all DBSets

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<Developer>();
        // other calls... etc here
    }
}

Web.config XML first line:

<?xml version="1.0" encoding="utf-8"?>

I have added the requisite MySQL dll's to the solution references. I don't see any spelling errors in my strings like many of the other questions on this topic.

Community
  • 1
  • 1
Chris
  • 119
  • 8

1 Answers1

0

The migrations settings I was working with were initialized to target a local sql instance. The unacceptable string format error was being thrown because the connection strings I was using were for MySQL protocol, rather than regular SQL.

I force re-enabled migrations specifically targeting my custom context. Doing this prevented the error from happening, because Migrations was now expecting a MySQL context and connection strings.

I used:

Enable-Migrations -ContextTypeName MYCONTEXT -Force
Chris
  • 119
  • 8