gpt4 book ai didi

sql-server - Entity Framework 核心-错误: keyword not supported: '"server'

转载 作者:行者123 更新时间:2023-12-02 11:18:59 28 4
gpt4 key购买 nike

我正在使用Entity Framework Core 2.1。我首先将实体类又称为数据库。当我尝试从其中一个数据库表中获取数据时,出现错误“服务器不支持关键字”。

我用谷歌搜索,看来我的连接字符串不正确。这是我的json文件中的设置

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

我看过其他类型的EF连接,例如
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""

我不确定.csdl,ssdl和msl。

任何帮助表示赞赏。谢谢。

错误:

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, Func
3 operation, Func3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable
1.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.ExceptionInterceptor
1.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).

最佳答案

简单地从连接字符串的开头和结尾除去\“就可以了。在这种情况下,您可以使用完整的连接字符串。

"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;"\;"


"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;"

关于sql-server - Entity Framework 核心-错误: keyword not supported: '"server',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52172897/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com