Efcore: Keyword not supported: 'userid'

Created on 25 Dec 2016  路  10Comments  路  Source: dotnet/efcore

I am using EF Core version 1.1.0
Below is my project.json file
``{
"version": "1.0.0-*",

"dependencies": {
"AS.BL.Contracts": "1.0.0-",
"AS.Core": "1.0.0-
",
"AutoMapper": "5.2.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.IdentityModel.Protocols": "2.1.0",
"NETStandard.Library": "1.6.1"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}``

when I use update-database below error is occurred

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'.

Database is not created yet.

Most helpful comment

It seems that your connection string format error .
please rewrite "userid" as "user id" (with a space) , I'm afraid .

All 10 comments

It seems that your connection string format error .
please rewrite "userid" as "user id" (with a space) , I'm afraid .

To check connection i created database manually without creating any table.
Below is my OnConfiguring function for DbContext Class

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var con = new SqlConnection(@"Server=DESKTOP-ED40Q7U\SQLEXPRESS;Database=AccountSoft;User Id=sa;PWD=secret1234;"); con.Open(); con.Close(); optionsBuilder.UseSqlServer(con); }

In this I am able to open connection successfully.
but when i use update-database from Package Manager Console Error Occured.
If required I can attach "Migrations" folder.

@nikunjratanpara
we can separate this into two questions:

  1. System.ArgumentException: Keyword not supported: 'userid'. ==> Does it appear again after "user id" with a space in it ?
  2. this is a new issue on how to create a new database with "dotnet ef" commands in Visual Studio PMC

as No.2 ,
two way to create database,
a. In the constructor method of ApplicationDbContext ("it's a sample"),
public ApplicationDbContext(){ Database.EnsureCreated(); }
build and run the code (with a new "ApplicationDbContext" instance)
b. use "dotnet ef" commands follow this.
hope it helps .^_^

@KalibGao Thanks for your prompt reply.

1. System.ArgumentException: Keyword not supported: 'userid'. ==> Does it appear again after "user id" with a space in it ?

Yes, I am using same connection string from starting .

2. this is a new issue on how to create a new database with "dotnet ef" commands in Visual Studio PMC

a. I will try after adding  Database.EnsureCreated();  which I am not calling in DbContext constructor.
b. I follows same blog as reference which you mentioned.

@KalibGao Thanks for your support

Database.EnsureCreated(); did the trick and database is created.

Still when I use update-database from "Package Manager Console" It gives the same error.

@nikunjratanpara As far as I know there is no place where EF Core could manufacture a connection string for SQL Server with a wrong keyword. The most likely explanation for this exception is that your application contains a different connection string somewhere else that is missing the space between "user" and "id".

Depending on what derived DbContext class the migrations commands are detecting at design-time and how that DbContext is being configured, the connection string could be located in one of several places, e.g. in code in the OnConfiguring() method of another DbContext class, in Startup.ConfigureServices(), in appsettings.json, in a custom implementation of IDbContextFactory or somewhere else entirely.

@divega Thanks for your input.

It turns out that after upgrading "Microsoft.NETCore.App" to 1.1.0 It requires "runtimes" configuration in "project.json" file and after adding that part, it create new directory "netcoreapp1.1" in bin/debug and after new build dlls are coping to new directory so when I use "update-Databse" command every time old dlls are used.

@nikunjratanpara do you mean that update-database is running with stale dlls and also with a stale connection string?

Yes, actually I am Using ASP.NET Core first time and I thought all dlls will be copied to bin/Debug automatically. but it is generated and copied to "netcoreapp1.1/win10-x64".

In the DB connection you might have specified "UserId". it should be as "User ID"

Was this page helpful?
0 / 5 - 0 ratings