Entity Framework Core - error: keyword not supported: '"server'

4

I am using Entity Framework Core 2.1. I scaffold my entity classes aka database first. When I try to get the data from one of the db tables, I get an error "keyword not supported for 'server'."

I googled and it looks like my connection string is not correct. Here it is setting in my json file

"DefaultConnection": "\"Server=myDb.com;Database=MyDb;user id=admin;Password=Password;MultipleActiveResultSets=true;Provider=System.Data.SqlClient"

I have seen other type of EF connection like

connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(local);initial catalog=test;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""

I am not sure about the .csdl, ssdl and msl.

Any help is appreciated. Thanks.

Error:

System.ArgumentException: Keyword not supported: '"server'.

at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary2 parsetable, String connectionString, Boolean buildChain, Dictionary2 synonyms, Boolean firstKey)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary2 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.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection() at Microsoft.EntityFrameworkCore.Internal.LazyRef
1.get_Value() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities[TOut,TIn](IEnumerable1 results, QueryContext queryContext, IList1 entityTrackingInfos, IList1 entityAccessors)+MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext() Exception thrown: 'System.ArgumentException' in Microsoft.EntityFrameworkCore.dll 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.2\System.IO.MemoryMappedFiles.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. The program '[3112] dotnet.exe' has exited with code -1 (0xffffffff).

sql-server
entity-framework
.net-core
asked on Stack Overflow Sep 4, 2018 by user1250264 • edited Sep 4, 2018 by marc_s

3 Answers

0

After playing with different connection string, here what I changed in my json to file to get it working

"DefaultConnection": "Server=myDb.com;Database=MyDb;user id=admin;Password=Password;
answered on Stack Overflow Sep 4, 2018 by user1250264 • edited Sep 4, 2018 by marc_s
0

This is because the connection strings have been replaced after scaffolding the identity. The replacement string may look very similar but has some escaped characters in it.

I had appSettings.Development.json, appSettings.Staging.json and appSettings.Production.json, each with DIFFERENT connection strings.

After scaffolding my Identity using an EXISTING dbContext, it had replaced the connection string in appSettings.json files with the one single connection string. I have no idea why it picked that one but I realised the string was escaped so

"Server=MYCOMPNAME\\SQLEXPRESS;...

had become

"\"Server=KRYTEN\\\\SQLEXPRESS;

and this is why we get the error.

answered on Stack Overflow Aug 13, 2019 by jamheadart
0

Simple removing \" from front and end of connection string will work. In this case you can use complete connection string.

"DefaultConnection": "\"Server=tcp:myDb.com,1433;Initial Catalog=MyDb;Persist Security Info=False;User ID=admin;Password=Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"\;"

to

"DefaultConnection": "Server=myDb.com,1433;Initial Catalog=MyDb;Persist Security Info=False;User ID=admin;Password=Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
answered on Stack Overflow Feb 26, 2020 by Snziv Gupta

User contributions licensed under CC BY-SA 3.0