Sto cercando di connettermi a SQL Server 2014 o 2016 da un'applicazione web ASP.NET Core 1.0 (Entity Framework Core). Sto ottenendo l'errore qui sotto. Qualche consiglio su come risolverlo.
Posso collegarmi con successo al DB dall'esploratore dell'oggetto di SQL Server di Visual Studio 2015. Tuttavia, la connessione dall'applicazione Web ha esito negativo. Né posso eseguire l' dotnet ef database update
.
Posso connettermi a LOCALDB.
La mia stringa di connessione è simile a:
"DefaultConnection": "Data Source=server;Initial Catalog=TestDb;Integrated Security=False;User ID=sa;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
L'errore che ottengo è Ottengo lo stesso errore su SQL Server 2014 e 2016:
An unhandled exception occurred while processing the request.
Win32Exception: The network path was not found
.ctor
SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
La traccia dello stack è:
Win32Exception: The network path was not found
.ctor
CreateConnection
CreatePooledConnection
CreateObject
UserCreateRequest
TryGetConnection
WaitForPendingOpen
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
GetResult
MoveNext in AccountController.cs
var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MoveNext
ThrowForNonSuccess
HandleNonSuccessAndDebuggerNotification
MoveNext
MODIFICA 1
Si noti che questa non è la stessa domanda di: Perché sto ricevendo "Impossibile connettersi al server - Un errore relativo alla rete o specifico dell'istanza"?
MODIFICA 2
Il tipo di questo progetto in cui ho problemi è ASP.NET Core Web Application (.NET Core ) .
Tuttavia, ho provato creando il progetto ASP.NET Core Web Application (.NET Framework ) e non ci sono stati problemi. Sono stato in grado di connettermi.
Qualche idea su cosa è diverso tra questi progetti?
Ho avuto un problema simile oggi. Sembra che la stringa di connessione .Net Core a SQL Server sia leggermente diversa dalle precedenti stringhe di connessione di SQL Server. Hai provato a utilizzare qualcosa di simile a quello specificato qui sul blog MSDN? :
using (var connection = new SqlConnection("Server=tcp:YourServer,1433;Initial Catalog=YourDatabase;Persist Security Info=True;"))
(Se scorri la pagina verso il basso fino all'intestazione secondaria 'Database relazionali' e 'SQL Server', troverai degli esempi.)
Se stai usando username e password nella stringa, puoi provare anche questo:
"Server=tcp:yourservername,1433;Initial Catalog=yourdbname;User ID=yourusername;Password=yourpassword;"