Windows services connecting to SQL Server - c#

I have a Windows service running in the server. When the clients in the domain connect to the service, it is able to connect to SQL Server 2008 R2 / SQL Server 2012 / SQL Server 2016. However, when the Windows service is accessed over the internet, it fails to connect to the SQL Server.
Service runs as Network Service and SQL Server has login rights Network Service. Otherwise even domain client accessing windows services will not be able to access.
It was working properly i.e connecting SQL Server when I used in the Windows service OLEDbConnection to access SQL Server. I changed to DBConnection as we want to support MySQL as well in addition to SQL Server, DB2 and Oracle. After changing to DBconnection, I have encountered this issue.
The error message 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)

Related

SQL SERVER:A network-related or instance-specific error occurred

I was using Microsoft SQL with asp.net MVC , it was working fine but today morning it gave me 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) (.Net SqlClient Data Provider)
I tried to Enable TCP/IP. I also started SQL in configuration manager but still cannot login to SQL Server 2014 using cloud server. It was working fine. I don't know what has happened to it.
Thanks
There is a really good YouTube vid at the bottom of this web-page so you can rule out a few more things - failing that I would have the server rebooted.
SQL Authority
In MS SQL Server Management Studio, have you checked the Properties of the SQL Server to ensure that Allow remote connections to the server is ticked?
If so then I would have to agree that it an on the Cloud Server rather than an issue with the SQL database.
Are you able to reboot the Cloud Server?
MS SQL Studio 2014 doesn't work very well with SQL 2005 or older if you running an old database version
You may want to ensure that the cloud server is allowing connections from your remote IP. It could be that your remote IP address has changed and you are no longer allowed access.
How to open the SQL database firewall for Microsoft Azure:
https://azure.microsoft.com/en-us/documentation/articles/sql-database-configure-firewall-settings/

Jumbox server connection

I have follow situation. I connect on a jumpbox server with my account domain\username and password from my computer. On jumpbox server I connect from SQL Server Management Studio on others servers, where I have databases, using Windows Authentication.
I want to write a Windows application on my computer that connect to databases but I receive 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
I put my domain on Window Credential and on application I use this string to
connect: connetionString="Server=myServerDatabase ;
Database= myDatabase; Integrated Security=SSPI; User
ID=myDomain/username;Password=MyPass"
If you have others idea how to connect or if it's possible to pass from jumpbox server and then connect to database server and then to database.

I don't connecton with my Azure SQL from ASP.NET

I'm new in azure cloud, so I have asp.net application. I want add ado.NET item. I try with connection string. Add connection there not run I add new connection there not run.
I don't understand. How add my entity framework classes to azure?
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: 40 - Error Could not open a connection a SQL Server ).
I new in asp.net too, so How I work with azure and asp.net?
You need to configure a firewall rule to enable you to connect to the database. You can do this from the portal.
How to configure firewall for database

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

i am developing a web application in visual studio 2012. and i have added a database file named as Database1.mdf into App_Data folder and i have given following connection string
Data Source=(LocalDB)\v11.0;AttachDbFilename="E:\asp.net mvc\storage\storage\App_Data\Database1.mdf";Integrated Security=True
after that i have written the code for inserting the data but at that i am getting the error like
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)
is there any mistake in the connection string?
Please help me in htis
Usually, for me, this indicates that SQL Server hasn't been configured correctly to receive remote calls. There are three things to check.
Your server instance is named correctly and you have permissions to it
That you are configured to receive remote connections
That SQL server is open on the the protocols you want to use
To check the second one, open up SQL Management Studio and select Properties on the server. Then check under "Connections" that "Remote Server Connections" is enabled.
To check the third, open up SQL Server Configuration Manager and make sure that "Client Protocols" TCP/IP is enabled as well as Named Pipes (depending on your network setup).
Your connection string should be written like this:
connectionString="DataSource=.\SQLEXPRESS; InitialCatalog=Database; AttachDBFilename=|DataDirectory|\Database.mdf; Integrated Security=SSPI;"

Using LINQ changing database from SQL Server 2008 R2 to SQL Server 2008

I've completed my webpage on my home computer and ready to upload it.
However I'm getting 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: Named Pipes
Provider, error: 40 - Could not open a
connection to SQL Server)
I know the connection string is correct. And I run a few different pages so I can connect to the other databases without problem.
This is the fist time I have used LINQ and I thought perhaps there was a setting it made that I need to change? LINQ is used in my DAL which is separate to the database, its just stored as DLLs in my bin folder...
My development server uses SQL Server 2008 R2 Express and my live server uses SQL Server 2008
I created database scripts to create the database. so I just ran them to downgrade the webpage.
Also In my DAL I just do this:
AHDBcontext db = new AHDBcontext(connectionstring);
var whatever = from s in suppliers
select s;
I always set connection string from the web.config file.
Any ideas?
Check the connection string.
Another way is following.
Go to Start Up => Microsoft Sql server 2008 => Configuratiuon Tools => Sql Server Configuration Manager
Check the Enabled status for client protocol.
restart the Browsing and other necessary services.

Categories

Resources