SQL Server not connecting via IIS - asp.net

I am getting the following error when I deploy my application to IIS:
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)]
What is interesting about this is that it is happening at the folder level. I have the same application, running on the same IIS server and it connects to the SQL server without issue - and the complied code is the same. The only difference is the folder that has the content. I am leaning towards a permission issue - but I did not change any of those.

Related

ASP.NET giving SQL Server errors. Possibly due to no log's configured on SQL Server Express

When I run my ASP.NET application I get this error in my browser:
The application could not connect to the database, please check the connection string in the web.config file and SQL server availability.
Original 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: SQL Network Interfaces, error: 25 - Connection string is not valid)
I checked Event Viewer and found this error:
initerrlog: Could not open error log file ''. Operating system error = 3(The system cannot find the path specified.).
I have SQL Server Express 2019 installed on my laptop so I checked SQL Server Configuration Manager and found the SQL Server process wasn't running so I tried to start it. It failed with this error:
Right now I'm assuming it's all part of the same issue.
I checked the start up parameters expecting to see something like -eC:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Log\ERRORLOG but there was no parameters and when I tried to add the the Add button greyed out.
I'm also unable to connect through SSMS:
TITLE: Connect to Server
Cannot connect to DESKTOP-GK2MRBG.
ADDITIONAL INFORMATION:
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) (Microsoft SQL Server, Error: 2)
For help, click: http://go.microsoft.com/fwlink?>ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=2&LinkId=20476
The system cannot find the file specified
BUTTONS:
OK
How do I resolve this?

Connection issue between Asp.Net 4.5 app and SQL Server 2012

I have a web forms application that is connecting to a SQL Server 2012 database. When I try to open the connection within the app I get this error:
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: 0 - No connection could be made because the target machine actively refused it.) ---> ...
I've checked and SQL server is configured to allow remote connections, TCP/IP is enabled, the server is up and I can connect to it via SSMS and Linqpad.
This is occurring when I run the application locally, hitting a local database. I know the connection string works, as I can use the login in SSMS to login and I have a linqpad query that is working with no problem using the same connection string. Also the error occurs when I try to open the connection (i.e. the connection is created successfully).
I'm guessing there is some access/security issues with my configuration of IIS, but I not finding it.
After a couple of frustrating days, I discovered the solution. The problem was that SQL server wasn't setup to use TCP/IP. This is configured in the Sql Server Configuration Manager, under the SQL Serer Network Configuration node, then Protocols for MSSQLSERVER. Make sure TCP/IP is enabled.

After upload my ASP.NET site cannot login to the admin panel

i have developed an asp.net web site for university. in visual studio i gave the server hosted sql server database connection string. not the local one. then when i run it on the local host with server hosted sql server database it allows me to log in to the admin panel.
but after i upload the same set of files which use the same server hosted database connection string, when i try to loging using asp.net template login from to my admin panel, it shows follow error. but in the local host the same hosted sql server worked properly.
i used here asp.net configuration to create the admin and only allowed administrator to access administration folder which has all the side administration pages.
please help me to fix this... thank you!!
Error message
Server Error in '/' Application.
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: 26 - Error Locating Server/Instance
Specified)
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.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: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Are you using an IP address for your connection? If the database is on the same server as your application you will need to use the home address "127.0.0.1" plus any port configuration you might have. Otherwise it wont find itself.
Same goes if your using a URL connection, you might need to add the URL to the server host file so it redirects back home.
The fact that you can connect from your local dosnt mean anything. Its clearly telling you the problem, your "SERVER" cant connect. Do you have Remote Desktop access? If you can, remote into the server and try connecting to your DB from there.

DB Connection ERROR after publishing the web application in IIS 6

After publishing web application in IIS 6 I am getting follwoing 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)
It runs fine in development server with same DB connection
Please help me
there can be multiple issues with this. But basic problem is that web server is not able to locate DB server.
Try below steps to figure out the exact issue
is the DB server pingable from your web server?
are you providing correct user while connecting to SQL server.
are you able to connect to the DB server from web server using the username you provided in your config file?
try all above and let me know your result.

Asp.Net With SQL Server And Asp.net Linq Application

I have an application that uses linq-to-sql with Sql Server Express 2008. When I use the DBML file in a separate DAL project and refer to it to my web project, on execute Sql Server shows this 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
But when I use the DBML in my web project, debugging is without any problem. But on IIS in Windows 7 64bit 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)
Do these two errors have the same cause? Is the connection string not correct?
I'd suspect that in the first case you have the connection string in the DAL project and not in your web project (where it belongs). Make sure you copy it to the web.config of your web project.
In the second case I think that that the machine hosting IIS tries to connect to the database on your own machine. If so, check the exception: make sure your SQL Express instance is configured to allow remote connections, that the IP protocol is enabled (named pipes if for local traffic), and that your machine is accessible to the IIS machine.
I think, Your connections string is wrong.
dont worry.
check your dbml's designer.cs file. in which you will find '<YourDBMLFile>DataContext()' Constructor.
and Change your Connection string. make sure your connectionstring is correct.

Resources