我正在尝试在NuGet中生成新的迁移脚本。键入add-migration Initial
后生成以下响应。注意:我的项目仍然编译并运行,没有错误......
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.
我一直在关注此问题的指南,以便与我的Google Cloud SQL服务器建立联系: Dynamic MySQL database connection for Entity Framework 6
我的连接字符串:
<add name="CCGamesGCloud.EntityFramework.Context" connectionString="Server=******;Database=*****;Uid=****;Pwd=*********"
providerName="MySql.Data.MySqlClient" />
我的EF字符串:
<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>
上下文类:
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第一行:
<?xml version="1.0" encoding="utf-8"?>
我已将必要的MySQL dll添加到解决方案参考中。我没有看到我的字符串中有任何拼写错误,就像关于这个主题的许多其他问题一样。
答案 0 :(得分:0)
我正在使用的迁移设置已初始化为目标sql实例。抛出了不可接受的字符串格式错误,因为我使用的连接字符串是用于MySQL协议,而不是常规SQL。
我强制重新启用专门针对我的自定义上下文的迁移。这样做可以防止错误发生,因为迁移现在需要MySQL上下文和连接字符串。
我用过:
Enable-Migrations -ContextTypeName MYCONTEXT -Force