“Connection string keyword ‘server’ is not supported in .NET Core.”

huangapple go评论75阅读模式
英文:

Connection string keyword 'server' is not supported in .NET Core

问题

你们的大学课程正在进行一个项目,之前已经建立了多次而没有错误。然而,最近的一些更改导致了这个错误的发生:

Microsoft.EntityFrameworkCore.Query[10100]
  在查询上遍历结果时发生了异常,上下文类型为'AdministrationAPI.Data.AppDbContext'。
  System.ArgumentException: 不支持连接字符串关键字'server'。可能的替代方法请参见https://go.microsoft.com/fwlink/?linkid=2142181。
     在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
     在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
     在System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
     在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
     在Microsoft.Data.Sqlite.SqliteConnectionFactory.GetPoolGroup(String connectionString)
     在Microsoft.Data.Sqlite.SqliteConnection.set_ConnectionString(String value)
     在Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
     在Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
     在Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
     在Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
     在Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
     在Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
     在Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
  System.ArgumentException: 不支持连接字符串关键字'server'。可能的替代方法请参见https://go.microsoft.com/fwlink/?linkid=2142181。
     在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
     在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
     在System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
     在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
     在Microsoft.Data.Sqlite.SqliteConnectionFactory.GetPoolGroup(String connectionString)
     在Microsoft.Data.Sqlite.SqliteConnection.set_ConnectionString(String value)
     在Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
     在Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
     在Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
     在Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
     在Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
     在Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
     在Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
未处理的异常。System.ArgumentException: 不支持连接字符串关键字'server'。可能的替代方法请参见https://go.microsoft.com/fwlink/?linkid=2142181。
   在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
   在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
   在System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
   在Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
   在Microsoft.Data.Sqlite.SqliteConnectionFactory.GetPoolGroup(String connectionString)
   在Microsoft.Data.Sqlite.SqliteConnection.set_ConnectionString(String value)
   在Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
   在Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
   在Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
   在Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
   在Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   在Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   在Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   在Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   在Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   在Microsoft.AspNetCore.Identity.RoleManager`1.RoleExistsAsync(String roleName)
   在Program.<Main>$(String[] args) in C:\Users\xxx\Documents\GitHub\xxx\xxx\Program.cs:line 102
   在Program.<Main>(String[] args)
PS C:\Users\xxx\Documents\GitHub\xxx\xxx>;

我并不确定问题出在哪里。以下是我们的连接字符串:

"ConnectionStrings": {
	"DefaultConnectionString": "server=localhost;User Id=root;password=password;database=ourproject;",
	"DefaultConnectionString_Select": "server=localhost;User Id=root;password=password;database=ourproject_application;",
	"SqliteMain": "Data Source=main.db",
	"SqliteProvider": "Data Source=provider.db",
	"OurprojectDB": "Data Source=SQL8005.site4now.net;Initial Catalog=db_a96e9a_ourproject001;User Id=db_a96e9a_ourproject001_admin;Password=mihighschool"
}

有人知道可能出了什么问题吗?

英文:

My college class is working on a project which we have already built several times without error. However, some recent change prompted this error to happen:

Microsoft.EntityFrameworkCore.Query[10100]
  An exception occurred while iterating over the results of a query for context type &#39;AdministrationAPI.Data.AppDbContext&#39;.
  System.ArgumentException: Connection string keyword &#39;server&#39; is not supported. For a possible alternative, see https://go.microsoft.com/fwlink/?linkid=2142181.
     at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
     at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
     at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
     at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
     at Microsoft.Data.Sqlite.SqliteConnectionFactory.GetPoolGroup(String connectionString)
     at Microsoft.Data.Sqlite.SqliteConnection.set_ConnectionString(String value)
     at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
     at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
     at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
     at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
     at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
     at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
     at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
  System.ArgumentException: Connection string keyword &#39;server&#39; is not supported. For a possible alternative, see https://go.microsoft.com/fwlink/?linkid=2142181.
     at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
     at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
     at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
     at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
     at Microsoft.Data.Sqlite.SqliteConnectionFactory.GetPoolGroup(String connectionString)
     at Microsoft.Data.Sqlite.SqliteConnection.set_ConnectionString(String value)
     at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
     at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
     at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
     at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
     at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
     at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
     at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
Unhandled exception. System.ArgumentException: Connection string keyword &#39;server&#39; is not supported. For a possible alternative, see https://go.microsoft.com/fwlink/?linkid=2142181.
   at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
   at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
   at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
   at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
   at Microsoft.Data.Sqlite.SqliteConnectionFactory.GetPoolGroup(String connectionString)
   at Microsoft.Data.Sqlite.SqliteConnection.set_ConnectionString(String value)
   at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Identity.RoleManager`1.RoleExistsAsync(String roleName)
   at Program.&lt;Main&gt;$(String[] args) in C:\Users\xxx\Documents\GitHub\xxx\xxx\Program.cs:line 102
   at Program.&lt;Main&gt;(String[] args)
PS C:\Users\xxx\Documents\GitHub\xxx\xxx&gt;

I don't really know where the issue is. Here's our connection strings:

&quot;ConnectionStrings&quot;: {
	&quot;DefaultConnectionString&quot;: &quot;server=localhost;User Id=root;password=password;database=ourproject;&quot;,
	&quot;DefaultConnectionString_Select&quot;: &quot;server=localhost;User Id=root;password=password;database=ourproject_application;&quot;,
	&quot;SqliteMain&quot;: &quot;Data Source=main.db&quot;,
	&quot;SqliteProvider&quot;: &quot;Data Source=provider.db&quot;,
	&quot;OurprojectDB&quot;: &quot;Data Source=SQL8005.site4now.net;Initial Catalog=db_a96e9a_ourproject001;User Id=db_a96e9a_ourproject001_admin;Password=mihighschool&quot;
}

Does anyone have an idea what might have gone wrong?

答案1

得分: 1

根据引用文件SQLite连接字符串

您必须使用Data Source而不是Server

英文:

According to referenced document SQLite Connection strings

you have to use Data Source instead of Server.

答案2

得分: 0

如果您正在尝试连接到 SQL Server,请将 Server 替换为 Data Source

英文:

If you're trying to connect to SQL Server, then replace Server with Data Source

huangapple
  • 本文由 发表于 2023年4月17日 00:32:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定