英文:
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 'AdministrationAPI.Data.AppDbContext'.
System.ArgumentException: Connection string keyword 'server' 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 'server' 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 'server' 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.<Main>$(String[] args) in C:\Users\xxx\Documents\GitHub\xxx\xxx\Program.cs:line 102
at Program.<Main>(String[] args)
PS C:\Users\xxx\Documents\GitHub\xxx\xxx>
I don't really know where the issue is. Here's our connection strings:
"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"
}
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论