c# - 使用 visual studio 和 entity framework core 5.0.2 连接到 MSSQL Server developer edition

标签 c# sql-server entity-framework-core visual-studio-2019

我下载了一个 AdentureWorks2019.bak,并在 SQL Server Management Studio 中恢复了它。当我尝试使用以下命令在 Visual Studio 2019 中构建基架时:

Scaffold-DbContext 'Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=AdventureWorks;Trusted Connection=True;'  Microsoft.EntityFrameworkCore.SqlServer

我收到以下警告:

To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.

然后出现如下错误:

 PM> Scaffold-DbContext 'Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=AdventureWorks;Trusted Connection=True;'  Microsoft.EntityFrameworkCore.SqlServer
Build started...
Build succeeded.
To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
System.ArgumentException: Keyword not supported: 'trusted connection'.
   at Microsoft.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
   at Microsoft.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
   at Microsoft.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
   at Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
   at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
   at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluarlize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Keyword not supported: 'trusted connection'.

我曾尝试寻找解决方案,但没有成功。如果有人能提供帮助,我将不胜感激!

最佳答案

连接字符串关键字是“Integrated Security”或“Trusted_Connection”。

不是“可信连接”

查看文档:SqlConnection.ConnectionString

关于c# - 使用 visual studio 和 entity framework core 5.0.2 连接到 MSSQL Server developer edition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65982886/

相关文章:

sql-server - VS 2019 SSIS包无法添加SQL Server

sql-server - SQL Server 功能等同于 PostgreSQL "in"

c# - 网络核心 : Generic Repository Primary Id Key Performance in Entity Framework

c# - CaSTLe Windsor 在哪里以及如何建立伐木设施

c# - 使用 .Net 调用 Servicenow Web 服务

java - 在其他计算机上运行时导出的 .jar 给出 "No suitable driver found for jdbc"

c# - 如何从 Dotnet EF 中删除唯一索引?

asp.net - 将 Razor 页面上的下拉列表绑定(bind)到数据库表

c# - 带有 XmlSerializer 的 DefaultParameterValue 属性?

C# 监听器线程上的 CPU 使用率高,休眠未命中断开连接