I have a clean .NET Core 2.0 webapp up and running on a Ubuntu 16.04 server using nginx.
My appsettings.json
contains:
"ConnectionStrings": {
"Database": "Server=myip;Database=mydb;Uid=myuser;Pwd=mypassword",
"providerName": "Sql.Data.SqlClient"
},
I've installed SQL Server on a separated server, it's working properly:
user@server:~$ sudo systemctl status mssql-server.service
● mssql-server.service - Microsoft SQL Server Database Engine
Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2018-04-18 19:05:37 CEST; 20min ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 1016 (sqlservr)
CGroup: /system.slice/mssql-server.service
├─1016 /opt/mssql/bin/sqlservr
└─1197 /opt/mssql/bin/sqlservr
I've managed to deploy my application successfully, it's working because I have interaction with my models. However, when I try to run the same project (from the server) locally on my machine, it shows the following error in the console:
Executing handler method OnGetAsync with arguments ((null)) - ModelState is Valid
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.0.2-rtm-10011 initialized 'WebappContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
An unhandled exception has occurred while executing the request
System.Data.SqlClient.SqlException (0x80131904): 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: TCP Provider, error: 40 - Could not open a connection to SQL Server)
So my main question is: Why can't I connect to the database when running the same (deployed) project when it's running locally on my machine?
Check your firewall you must allow connecting to C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS2014\MSSQL\Binn\sqlservr.exe
Make sure the connection string is the correct for your machine as it may be different from the database on your server
User contributions licensed under CC BY-SA 3.0