我是一个脚手架我的数据库时收到以下错误?

时间:2017-02-06 07:28:26

标签: asp.net entity-framework asp.net-core

Scaffold-DbContext "'server=MyPc\SQLEXPRESS;Database=Test;Encrypt=True;TrustServerCertificate=False;'" 'Microsoft.EntityFrameworkCore.SqlServer' -Verbose
Build started...
Build succeeded.
Setting app base path C:\DotNetCoreApps\URShopi\src\URShopi\.\bin\Debug\netcoreapp1.0
System.ArgumentException: Keyword not supported: ''server'.
   at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 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.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqlServerScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContextAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ScaffoldContextImpl>d__22.MoveNext()
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Keyword not supported: ''server'.

2 个答案:

答案 0 :(得分:0)

从连接字符串中删除单引号

答案 1 :(得分:0)

首先添加以下nuget包:

Install-Package Microsoft.EntityFrameworkCore.SqlServer

Install-Package Microsoft.EntityFrameworkCore.Tools –Pre

Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design

之后打开project.json文件并进行以下更改

在依赖项下添加:

"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",

&#34; Microsoft.EntityFrameworkCore.SqlServer.Design&#34;:&#34; 1.0.0&#34;, &#34; Microsoft.EntityFrameworkCore.Tools&#34;:&#34; 1.0.0-preview2-final&#34;,

并在工具下添加:

"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",

进行更改后保存文件。

最后再次运行命令 - 在程序包管理器控制台中:

Scaffold-DbContext&#34; Server =。; Database = dbname; Trusted_Connection = True;&#34; Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models