不支持关键字:'userid'错误

时间:2018-05-18 09:43:50

标签: asp.net-core .net-core asp.net-core-mvc

我克隆了这个源代码(https://code.msdn.microsoft.com/Onion-Architecture-In-9c58c06d)。我正在使用mysql和我的连接字符串

  "ConnectionStrings": {
    "DefaultConnection": "server=localhost;userid=root;pwd=root;port=3306;database=ddd;sslmode=none;"
  },

在我的包管理器控制台命令Add-Migration FirstMigration成功了,Update-Database正在抛弃我

System.ArgumentException: Keyword not supported: 'userid'.
   at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
   at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
   at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
   at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Keyword not supported: 'userid'.

我做错了吗?

2 个答案:

答案 0 :(得分:0)

这不是SQL Server的有效连接字符串。 userid应为User IDpwd应为Password。例如

Server=servername\instancename;Database=dbname;User Id=username;Password=password;

有关更多示例,请参阅: https://www.connectionstrings.com/sql-server/

答案 1 :(得分:0)

您引用的代码使用MsSQL。如果您希望使用mysql,则需要更改代码。

在参考代码中,有一个名为<mat-row _ngcontent-c1="" class="mat-row ng-star-inserted" role="row"> <!----> </mat-row> 的类。

方法Startup.cs中有一行需要更改。

目前该行说明:

public void ConfigureServices(IServiceCollection services)

简而言之:将类型为services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 的DbContext添加到services集合中。要实例化实例,请使用以下选项:

带有名为ApplicationContext

的连接字符串的

UseSqlServer

您需要更改这些选项以反映mysql。

可能的解决方案

  1. 安装包MySql.Data.EntityFrameworkCore
  2. 将行更改为:
  3. services.AddDbContext(options => options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")));