本文介绍了在EF核心脚手架中获取SQL连接字符串错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关背景信息,我在Arch Linux VScode上运行.NET core,并且在Arch Linux上也运行SQL Server。当我通过 sqlcmd 或通过VScode SQL扩展连接到服务器时,一切正常。

For background info, I'm running .NET core on Arch Linux VScode and I also have SQL Server running on Arch Linux. When I connect to the server via sqlcmd or through the VScode SQL extension, everything works fine.

仅当脚手架出现错误时,我的连接字符串可能才错误,因此我进行了搜索并尝试了一切。

Only when scaffolding am I getting errors, so my connection string is probably wrong, and I've searched and basically tried everything within my grasp. Any help would be much appreciated, thanks in advance.

当我运行命令时

[wasiim@wasiim-PC WebApiServerApp]$ dotnet ef dbcontext scaffold "Server=wasiim-PC;Database=ConkerDb;User Id=sa;Password=********" Microsoft.EntityFrameworkCore.SqlServer -o Models -c ConkerDbContext -v

我收到此错误:

System.Net.Internals.SocketExceptionFactory + ExtendedSocketException(00000005,6):没有此类设备或地址

System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 6): No such device or address

在System.Net.Dns.InternalGetHostByName(字符串主机名)

在System.Net.Dns.GetHostAddresses(字符串主机名或地址)

在System.Data.SqlClient.SNI.SNITCPHandle.Connect(字符串serverName,Int32端口,TimeSpan超时)

在System.Data.SqlClient.SNI.SNITCPHandle..ctor(字符串serverName, Int32端口,Int64 timerExpire,对象callbackObject,布尔并行)

at System.Net.Dns.InternalGetHostByName(String hostName)
at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
at System.Data.SqlClient.SNI.SNITCPHandle.Connect(String serverName, Int32 port, TimeSpan timeout)
at System.Data.SqlClient.SNI.SNITCPHandle..ctor(String serverName, Int32 port, Int64 timerExpire, Object callbackObject, Boolean parallel)

我也尝试过这样做

[wasiim@wasiim-PC WebApiServerApp]$ dotnet ef dbcontext scaffold "Server=(wasiim-PC)\MSSQLSERVER;Database=ConkerDb;User Id=sa;Password=********" Microsoft.EntityFrameworkCore.SqlServer -o Models -c ConkerDbContext -v

然后我得到了错误

在System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity身份,SqlConnectionString connectionOptions, SqlCredential凭据,对象providerInfo,字符串newPassword,SecureString newSecurePassword,布尔型redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData,布尔值applyTransientFaultHandling,字符串accessToken)

位于System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPool ,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection owningConnection,DbConnectionOptions userOptions)

at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)

mssql错误日志

错误日志未显示任何我已进行的连接尝试,因此我假设它未建立连接,并且该服务正在运行。我ping了wasiim-PC,ping了本地主机,ping了127.0.0.1,它们都工作正常。

the errorlog display nothing about any of the connection attempts I've made so I'm assuming it didn't make a connection, and yes the service is running. I pinged wasiim-PC, pinged localhost, pinged 127.0.0.1 they're all working just fine.

[wasiim@wasiim-PC log]$ sudo cat errorlog
2019-07-04 14:53:24.34 Server      Microsoft SQL Server 2017 (RTM-CU15) (KB4498951) - 14.0.3162.1 (X64) 
        May 15 2019 19:14:30 
        Copyright (C) 2017 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Arch Linux)
2019-07-04 14:53:24.35 Server      UTC adjustment: -5:00
2019-07-04 14:53:24.35 Server      (c) Microsoft Corporation.
2019-07-04 14:53:24.36 Server      All rights reserved.
2019-07-04 14:53:24.36 Server      Server process ID is 32.
2019-07-04 14:53:24.36 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2019-07-04 14:53:24.37 Server      Registry startup parameters: 
         -d /var/opt/mssql/data/master.mdf
         -l /var/opt/mssql/data/mastlog.ldf
         -e /var/opt/mssql/log/errorlog
2019-07-04 14:53:24.38 Server      SQL Server detected 1 sockets with 4 cores per socket and 8 logical processors per socket, 8 total logical processors; using 8 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2019-07-04 14:53:24.39 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2019-07-04 14:53:24.39 Server      Detected 12632 MB of RAM. This is an informational message; no user action is required.
2019-07-04 14:53:24.40 Server      Using conventional memory in the memory manager.
2019-07-04 14:53:24.41 Server      Large Page Allocated: 32MB 
2019-07-04 14:53:24.92 Server      Buffer pool extension is already disabled. No action is necessary. 
2019-07-04 14:53:25.16 Server      InitializeExternalUserGroupSid failed. Implied authentication will be disabled.
2019-07-04 14:53:25.16 Server      Implied authentication manager initialization failed. Implied authentication will be disabled.
2019-07-04 14:53:25.18 Server      Successfully initialized the TLS configuration. Allowed TLS protocol versions are ['1.0 1.1 1.2']. Allowed TLS ciphers are ['ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:!DHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA'].
2019-07-04 14:53:25.21 Server      The maximum number of dedicated administrator connections for this instance is '1'
2019-07-04 14:53:25.22 Server      Node configuration: node 0: CPU mask: 0x00000000000000ff:0 Active CPU mask: 0x00000000000000ff:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2019-07-04 14:53:25.22 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2019-07-04 14:53:25.23 Server      In-Memory OLTP initialized on standard machine.
2019-07-04 14:53:25.34 Server      Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
2019-07-04 14:53:25.35 Server      Query Store settings initialized with enabled = 1, 
2019-07-04 14:53:25.35 spid6s      Starting up database 'master'.
2019-07-04 14:53:25.35 Server      Software Usage Metrics is disabled.
2019-07-04 14:53:25.57 spid6s      Resource governor reconfiguration succeeded.
2019-07-04 14:53:25.57 spid6s      SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2019-07-04 14:53:25.58 spid6s      SQL Server Audit has started the audits. This is an informational message. No user action is required.
2019-07-04 14:53:25.67 spid6s      SQL Trace ID 1 was started by login "sa".
2019-07-04 14:53:25.69 spid6s      Server name is 'wasiim-PC'. This is an informational message only. No user action is required.
2019-07-04 14:53:25.72 spid24s     Always On: The availability replica manager is starting. This is an informational message only. No user action is required.
2019-07-04 14:53:25.72 spid22s     Starting up database 'msdb'.
2019-07-04 14:53:25.72 spid23s     Starting up database 'ConkerDb'.
2019-07-04 14:53:25.72 spid9s      Starting up database 'mssqlsystemresource'.
2019-07-04 14:53:25.73 spid24s     Always On: The availability replica manager is waiting for the instance of SQL Server to allow client connections. This is an informational message only. No user action is required.
2019-07-04 14:53:25.74 spid9s      The resource database build version is 14.00.3162. This is an informational message only. No user action is required.
2019-07-04 14:53:25.78 spid9s      Starting up database 'model'.
2019-07-04 14:53:26.02 spid23s     Parallel redo is started for database 'ConkerDb' with worker pool size [4].
2019-07-04 14:53:26.02 spid19s     A self-generated certificate was successfully loaded for encryption.
2019-07-04 14:53:26.03 spid19s     Server is listening on [ 'any' <ipv6> 1433].
2019-07-04 14:53:26.04 spid19s     Server is listening on [ 'any' <ipv4> 1433].
2019-07-04 14:53:26.04 Server      Server is listening on [ ::1 <ipv6> 1434].
2019-07-04 14:53:26.04 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
2019-07-04 14:53:26.04 Server      Dedicated admin connection support was established for listening locally on port 1434.
2019-07-04 14:53:26.05 spid19s     SQL Server is now ready for client connections. This is an informational message; no user action is required.
2019-07-04 14:53:26.08 spid9s      Polybase feature disabled.
2019-07-04 14:53:26.09 spid9s      Clearing tempdb database.
2019-07-04 14:53:26.13 spid6s      Parallel redo is shutdown for database 'ConkerDb' with worker pool size [4].
2019-07-04 14:53:26.15 Server      Failed to verify the Authenticode signature of 'C:\binn\secforwarder.dll'. Signature verification of SQL Server DLLs will be skipped. Genuine copies of SQL Server are signed. Failure to verify the Authenticode signature might indicate that this is not an authentic release of SQL Server. Install a genuine copy of SQL Server or contact customer support.
2019-07-04 14:53:26.38 spid9s      Starting up database 'tempdb'.
2019-07-04 14:53:26.63 spid9s      The tempdb database has 1 data file(s).
2019-07-04 14:53:26.64 spid24s     The Service Broker endpoint is in disabled or stopped state.
2019-07-04 14:53:26.65 spid24s     The Database Mirroring endpoint is in disabled or stopped state.
2019-07-04 14:53:26.67 spid24s     Service Broker manager has started.
2019-07-04 14:53:26.70 spid6s      Recovery is complete. This is an informational message only. No user action is required.
2019-07-04 14:58:44.68 spid51      Using 'dbghelp.dll' version '4.0.5'
2019-07-04 15:00:33.43 spid51      Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
2019-07-04 15:00:33.54 spid51      Using 'xplog70.dll' version '2017.140.3162' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.

更新:完全错误

Build成功了。
0警告
0错误

Build succeeded. 0 Warning(s) 0 Error(s)

已用时间00:00:03.18
dotnet exec --depsfile / home / wasiim / Documents / CodingProjects / ProjectConker / WebApiServerApp / bin / Debug / netcoreapp2.2 / WebApiServerApp.deps.json --additionalprobingpath /home/wasiim/.nuget/packages --runtimeconfig / home / wasiim / Documents / CodingProjects / ProjectConker /WebApiServerApp/bin/Debug/netcoreapp2.2/WebApiServerApp.runtimeconfig.json /home/wasiim/.nuget/packages/microsoft.entityframeworkcore.tools.dotnet/2.0.3/tools/netcoreapp2.0/ef.dll dbcontext支架服务器=(wasiim-PC)\MSSQLSERVER;数据库= ConkerDb;用户ID = sa;密码= come1517 Microsoft.EntityFrameworkCore.SqlServer -o模型-c ConkerDbContext --assembly / home / wasiim / Documents / CodingProjects / ProjectConker / WebApiServerApp /bin/Debug/netcoreapp2.2/WebApiServerApp.dll --startup-assembly /home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/bin/Debug/netcoreapp2.2/WebApiServerApp.dll --project-dir / home / wasiim /文件s / CodingProjects / ProjectConker / WebApiServerApp / --verbose --root-namespace WebApiServerApp
使用程序集 WebApiServerApp。
使用启动程序集 WebApiServerApp。
使用应用程序库 /home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/bin/Debug/netcoreapp2.2。
使用工作目录 / home / wasiim / Documents / CodingProjects / ProjectConker / WebApiServerApp。
使用根名称空间 WebApiServerApp。
使用项目目录 / home / wasiim / Documents / CodingProjects / ProjectConker / WebApiServerApp /。
查找提供程序'Microsoft.EntityFrameworkCore.SqlServer'的设计时服务...
使用提供程序'Microsoft.EntityFrameworkCore.SqlServer'的设计时服务。
查找程序集 WebApiServerApp引用的设计时服务。
找不到参考的设计时服务。
在程序集 WebApiServerApp中查找IDesignTimeServices实现...
未找到设计时服务。

Time Elapsed 00:00:03.18 dotnet exec --depsfile /home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/bin/Debug/netcoreapp2.2/WebApiServerApp.deps.json --additionalprobingpath /home/wasiim/.nuget/packages --runtimeconfig /home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/bin/Debug/netcoreapp2.2/WebApiServerApp.runtimeconfig.json /home/wasiim/.nuget/packages/microsoft.entityframeworkcore.tools.dotnet/2.0.3/tools/netcoreapp2.0/ef.dll dbcontext scaffold "Server=(wasiim-PC)\MSSQLSERVER;Database=ConkerDb;User Id=sa;Password=come1517" Microsoft.EntityFrameworkCore.SqlServer -o Models -c ConkerDbContext --assembly /home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/bin/Debug/netcoreapp2.2/WebApiServerApp.dll --startup-assembly /home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/bin/Debug/netcoreapp2.2/WebApiServerApp.dll --project-dir /home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/ --verbose --root-namespace WebApiServerApp Using assembly 'WebApiServerApp'. Using startup assembly 'WebApiServerApp'. Using application base '/home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/bin/Debug/netcoreapp2.2'. Using working directory '/home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp'. Using root namespace 'WebApiServerApp'. Using project directory '/home/wasiim/Documents/CodingProjects/ProjectConker/WebApiServerApp/'. Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'... Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'. Finding design-time services referenced by assembly 'WebApiServerApp'. No referenced design-time services were found. Finding IDesignTimeServices implementations in assembly 'WebApiServerApp'... No design-time services were found.

如您所见,在出现异常之前,我说没有找到设计时服务,这似乎是相关的,我不知疲倦地在网上搜索,但无法解决。

as you can see, before I get the exceptions it says No design-time services were found, it seems related, I searched around the web tirelessly but couldn't fix this. Hope someone can help me, thanks in advance.

推荐答案

我运行了它,但这次我想它才起作用

I ran this and it just worked this time I guess

 dotnet ef dbcontext scaffold "Server=wasiim-PC;Database=ConkerDb;User Id=sa;Password=*********" Microsoft.EntityFrameworkCore.SqlServer -o Models -c ConkerDbContext -v

这篇关于在EF核心脚手架中获取SQL连接字符串错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:27