I build a new .net Core Web API with connection to SQL DB. I have problems to connect the API with my Database I tried a local DB \"DefaultConnection\": \"Server=(loca
The Problem in this case was the instance Server=192.168.1.XXX\\SQL2012;
. I don't know why but the system can't handle it. I use another Server instead (without instance).
Real solutions are welcome.
In my case the database was accessible via ASP.NET Web API and Windows Forms app. But the .Net Core API wasn't working.
The solution to the problem is to add port number in the connection string.
For e.g. The connection string specified below is example of the .NET Framework app.
data source=SERVER\SQLSERVER2017;initial catalog=DBNAME;persist security info=True;user id=ADMIN;password=ADMIN123;MultipleActiveResultSets=True;App=EntityFramework
I followed this link to set port number to the DB instance.
The port number after comma is the key.
So change connection string to something like this:
Server=SERVER\\SQLSERVER2017,1433;Database=DBNAME;User Id=ADMIN; Password=ADMIN123;MultipleActiveResultSets=True;
We hit a similar (or identical?) issue. .NET Core didn't work with a connection string but .NET Framework worked just fine with that same string. It turned out to be because our connection string was using an SQL Alias rather than the IP hostname of the database server, and .NET Core dropped SQL Alias support because it was too Windowsy/registry-y.
Changing the connection string to use the IP hostname or number resolved the issue.