EF Can't Find Database on Production - sql-server

Info
Project is ASP.NET Core 5.0, ORM is EF, DB is SQL Server
Problem
On Development, our database is accessible but on production its not!
Connection String
Is set in appsettings.json and its:
"MyConnectionString": "Data Source=MyDomain.com;Initial Catalog=MyDB;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD"
When we run the project in Visual Studio with this connection string, everything is fine, but it fails when it's published to the host.
The error is:
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)
Any suggestions?
Thanks in advance.

Certainly not in the production environment.
Asha, did you enter the string connection in the appsetting file in the Development section? Or in the production section

Related

ASPNET web with authentication does not work on the server

I am currently working on a ASP.NET Framework project. I have just added authentication with Microsoft Identity based on Microsoft´s templates.
A local DB file is generated in App_Data with the authentication data. I changed the file to the C:/ disk to put the same file on the same location in the server.
My Web.config files has the following line for the connection:
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=C:\DB\aspnet-users.mdf;Initial Catalog=aspnet-users;Integrated Security=True"
providerName="System.Data.SqlClient" />
In my local machine, this works perfectly fine, all the functionalities. However, after the deployment on the server, I try to register unsuccessfully. I am getting the following errors:
[Win32Exception (0x80004005): The system cannot find the file specified]
[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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
The publishing method is "File System", this method does not support database publishing according to VS.
Thank you!

asp.net Core 3.1.5 app cannot access database on server from web deploy publish

I have a Blazor Web Assembly app which I have publishing to a server running Windows Server 2019 with the database on MSSQL Server 2019 Express Edition.
The web app is using AspNetCore 3.1.5 with EntityFrameworkCore 3.1.5. Locally the app runs fine through self-hosting and IIS Express through Visual Studio 2019.
I can also run migrations to the servers database and seed using the following connection string through the PCM using update-database;
"Data Source=IPADDRESS;Initial Catalog=DATABASENAME;Integrated
Security=False;Persist Security Info=False;User
ID=USER;Password=PASSWORD;MultipleActiveResultSets=true;"
however after I publish the app to the server, when I attempt to log into the app i receive the following error;
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)
the only difference to the connection string on publish is that the IP become local host in my appsettings.release.json;
"Data Source=localhost;Initial Catalog=DATABASE;Integrated Security=False;Persist Security Info=False;User ID=USER;Password=PASSWORD;MultipleActiveResultSets=true;"
For completeness I have also attempted to add in the port number to the connection string;
"Data Source=localhost,1433;Initial Catalog=DATABASE;Integrated Security=False;Persist Security Info=False;User ID=USER;Password=PASSWORD;MultipleActiveResultSets=true;"
Finally I can confirm I can login with the same credentials using MSSQL Management Studio with localhost with RDP on the server.
I also attached the about info from management studio for information;
EDIT Updated Information
Following on from comments below here is a screenshot of the SQL Configuration Manager;
Can anyone direct me as to why its not connecting?

IIS can't connect to SQL Server, but an external PC can

My VB.Net code connects to SQL Server. On my PC, it succeeds. On IIS running on the same machine as SQL Server, it fails. Any ideas?
I've tested:
I've tried IP address and server name. Same result.
I've tried Integrated Security and I've tried username/password. Same result.
On the server machine, Excel and SSMS can connect to SQL server using the same server name, username and password.
The fact that my PC can connect excludes many common problems including: ip address, server name, port, firewall, turn on sql server, connection string, credentials, permissions, sql roles.
Server (IIS and SQL) info: VB.Net, connection string providerName="System.Data.SqlClient", Windows Server 2008 SP2.
My PC info: Run website in Visual Studio 2019. Connects to same DB using same connection string (not local db and not as a different user).
Code (fails on second line):
oConn = ConnectionService.DatabaseName.Connect
oConn.Open()
Connection string: connectionString="Data Source=IP Address\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=False;Persist Security Info=False;User ID=Username;Password=Password;" providerName="System.Data.SqlClient"
Error message: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
Oops. Right after posting this, I found out Web.Config pointed to a different connection string. That should explain and solve everything. I had checked Web.Config, but it turns out that that wasn't the one this server was using.

How to access a mdf file without Sql Server

I'm working on one Windows forms application using one .mdf file. And I have Sql Server 2008 installed in my machine , it is working fine in my machine. Now I need to install this application in Client's machine, Client's machine don't have Sql Server if they try to access this getting Network related exception, ie,
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)
and this is my connection string in app.config file,
<add name="CustomConnection" connectionString="Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=120;User Instance=True;AttachDbFilename=C:\Users\[username]\AppData\Roaming\Smart\App_Data\SampleDB.mdf" providerName="System.Data.SqlClient" />
Can we access the .mdf file without Sql Server instance? If yes how can we set the ConnectionString value.
Thanks,
Abhishek

Local IIS Web server cannot connect to SQL Server

When I use the local IIS Web server, my ASP.NET MVC application is unable to connect to SQL Server. The database is on another server. However, if I use the Visual Studio Development Server, it works just fine.
Anyone know what settings I'm missing? Should something change in my Web.config?
Yes, TCP/IP is enabled on SQL Server.
Here is the error I get -
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)
Here is my connection string -
connectionString="
SERVER=servername;
Initial Catalog=dbname;
User ID=userid;
Password=passwd"
providerName="System.Data.SqlClient"
I think you need to use IP address to connect remote database something like SERVER=59.230.212.12 in connection string. Try to connect database in management studio from where your IIS is installed . then use same setting in connection string .

Resources