Windows service network error - c#

I have made a windows service and through that service I am doing operations on the database. The machine that I have installed the service is in India and the server is in Singapore. When this service runs I get an error such as
" 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 have a connection string such as
return "server=122.0.122.222,5222;database=ABCD;user id=abc101;password=xyz";
this is in a function that is returning a string. I am catching this string in another string and passing it to the connection object.M I doing anything wrong here.?
But I have tested this service at my house. It works just fine. But when deployed at clients end I get the above error. Any idea why this mite be happening.? Is it related to internet connection but the internet connection is fine. DO I have to give some permissions from my service to make a connection or the IT team of the client should have to give some permissions at their end.?
Please help.
Thanks In advance

Related

Cannot Connect to SQL Server from Another Computer

I have been going at this for hours, but have had no success with the current posts out there.
Tried methods:
Enabling TCP
Allowing Remote Connections for the database
Adding new inbound and outbound rules
All these things still do not let me login from my other computer. When I connect on my main computer, everything is instant, but when I tried on my secondary one, it takes a long time before giving me the 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) (Microsoft SQL Server, Error: 1326)
Is there anyway of fixing this? I don't think watching more Youtube tutorials will help.

Intermittant SQL Server connection Issues

I maintain a system of automated data processing machines which run processes written in C# that are controlled by an SQl Server 2014 Enterprise Edition Database. Several times a day all of the processes on one machine will start receiving the following error:
An error has occurred. Details of the exception: 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) Unable to connect to SQL Server database.
All processes on the machine will experienc the same error when attempting to contact the database. After 10 or 15 minutes the machine will be able to connect again. While this is happening other machines on the same network will be able to connect no problem. We have checked the database - SQL Server is running - it is not blocked it is accepting connection, the instance name is correct. This is an intermittant problem that does not affect all machines connecting to the database but when it affects one - all processes experience the error. I have searched on this message and all the answers I have found are for constant failures - not intermittant like I am experiencing.
UPDATE
Found this on another question - Am testing now looks good:
The problem was that SQL was configured to allow both TCP and Named Pipes. Sometimes it would try and connect with the latter which doesn't use the standard SQL port. The solution was to prefix the data source/server in the connection string with Data Source=tcp:xxx.xxx.xx.xxx to always ensure it connects via TCP
The problem was that SQL was configured to allow both TCP and Named Pipes. Sometimes it would try and connect with the latter which doesn't use the standard SQL port. The solution was to prefix the data source/server in the connection string with Data Source=tcp:xxx.xxx.xx.xxx to always ensure it connects via TCP

Failed to connect to azure sql database with connection string [duplicate]

I'm very frustrated. I have a website running on Visual Web Developer 2008 Express with my local database, everything works great. I also have the same web site running on a production server. Everything was working great but tonight I did a "reset" on production.
I deleted a couple of table, re-created them and inserted data. Everything was ok at this time.
I deleted ALL the files via the FTP.
I used the module called "Copy website" in visual studio and copy the site to the website via FTP.
When I log on my website, here is the error I got:
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)
Nothing has changed related to SQL connection, this is OLD code that I always used.
My website is completely paralysed because of this and I feel sick inside because I feel there is nothing I can do.
Can anyone help me please?
Your connection string was probably overriden when you copied your new website version on the server. Please check the connection string in web.config and see if it is valid.
If you are connecting from Windows Machine A to Windows Machine B (server with SQL Server installed) and are getting this error, you need to do the following:
On Machine B:
Turn on the Windows service called "SQL Server Browser" and start the service
In Windows Firewall:
enable incoming port UDP 1434 (in case SQL Server Management Studio on machine A is connecting or a program on machine A is connecting)
enable incoming port TCP 1433 (in case there is a telnet connection)
In SQL Server Configuration Manager:
enable TCP/IP protocol for port 1433
I've resolved the issue. It was due to the SQL browser service.
Solution to such problem is one among below -
Check the spelling of the SQL Server instance name that is specified in the connection string.
Use the SQL Server Surface Area Configuration tool to enable SQL Server to accept remote connections over the TCP or named pipes protocols. For more information about the SQL Server Surface Area Configuration Tool, see Surface Area Configuration for Services and Connections.
Make sure that you have configured the firewall on the server instance of SQL Server to open ports for SQL Server and the SQL Server Browser port (UDP 1434).
Make sure that the SQL Server Browser service is started on the server.
link - http://www.microsoft.com/products/ee/transform.aspx?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-1
check forthe followings :
Make sure your database engine is configured to accept remote connections
• Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
• Click on Surface Area Configuration for Services and Connections
• Select the instance that is having a problem > Database Engine > Remote Connections
• Enable local and remote connections
• Restart instance
Check the SQL Server service account
• If you are not using a domain account as a service account (for example if you are using NETWORK SERVICE), you may want to switch this first before proceeding
If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your ASweb P.NET application
• Usually the format needed to specify the database server is machinename\instancename
• Check your connection string as well
the cause is that SQL SERVER is stopped from services.msc
a solution for this problem could be starting SQL SERVER from services.msc
I recently had this problem and it ended up being a port issue. My production SQL Server was set up at to be port 1427 instead 1433.
Just change the connection string to be
...data source=MySQLServerName,1427;initial catalog=MyDBName...
Hope this helps anyone who might be seeing this same issue.
I had the same problem with SQL Server 2008 R2 and when I checked "SQL Server Configuration Manager" My SQL Server instance had Stopped. Right Clicking and Starting the Instance solved the issue.
we have to enable TCP/IP property in sql server configuration manager
If your server was working and suddenly started erroring out, your server/instance stopped and connection settings were changed somehow.
For SQL Server 2008 here is how you can fit this:
Goto Start > All Programs > SQL Server 2008 > Configuration Tools > SQL Server Configuration Manager > SQL Server Services.
And here you'll see all the instances and their state.
The state of the instance you were trying to connect can be stopped here.
Double click on the instance and then click on connect.
It will connect and now go back and run your application, you will be able to connect with no error.
This solution assumes the error is not being caused by something wrong in your connection string.
In my case it was a very silly error. I was using a library to read the connection string out of a config file, and I forgot to double back slash.
For example I had:
localhost\sqlexpress which was read as localhostsqlexpress
when I should rather have had
localhost\\sqlexpress note the \
I had same problem regarding that i.e A network-related or instance-specific error occurred while establishing a connection to SQL Server.
I was using SQL Server 2005 (.\sqlexpress)` and worked fine but suddenly services stopped and gave me error.
I solved it like this,
Start -> Search Box - > Sql Configuration Manager -> SQL Server 2005 Services >and just Change Your SQL Server (SQLEXPRESS) State to Running by right clicking that service Sate.
I solved this issue by running the following command in an elevated command prompt as specified in this post.
net start mssqlserver
I had the same problem but found that it was because the password for my Service Account for the Database Engine had expired. The solution was to login to that account, fix this, then set the account so password never expires.
My remote sql server was expecting connection at a different port and not on the default 1443.
The solution was to add a "," after your sql server IP and then add your port like so 129.0.0.1,2995 (Check the " , " after server IP)
Please find the image for reference below.
I had the same error, and it turned out .NET created a database on localhost which I wasn't aware of. When I tried to get the site live it didn't create the database, so the code was pointing to a database that was non existent.
Hopefully this might help some other people out trying to troubleshoot.

WCF database connection working but fails when accessing database from WPF

I have a weird error occurring i've hit a brick wall with. I have my WCF service hosted on my web host, I can access this fine. I have a database set up on my web host and I have created the connection string to the database within my WCF web.config.
When I test the database connection to the database on the live server from my local WCF project the connection works fine. When I run my WPF application, it creates a contract with my WCF service (WPF app is local and WCF is live) I get the
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)"
I really don't understand how I can connect to the database from my local WCF project but not from my live one? Anyone got any tips on how to either resolve this or even how to identify where the issue is occurring?
RESOLVED: Apologies for wasting your time but I had the database connection string hardcoded in a configuration file as well as in the web.config which is what was causing the problem. I meant to fix this before and forgot all about it.

Desktop application cannot connect to database but web application can

I have written a C# desktop (winforms) application which is essentially a clone of a web application I wrote. The web application is able to talk back and forth with the database just fine. However, when I install the desktop application, I get the following error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server
I am using the exact same connection string in the desktop application as I am using in the web app which looks like this:
"Data Source=tcp:s08.winhost.com;Initial Catalog=THEDATABASE;
User ID=USERNAME;Password=******;Integrated Security=False;"
I am unable to use SQL Server Configuration Manager as my databases are hosted on Winhost.com. However they have made it clear to me that the proper ports are open, named pipes are on and SQL Browser is configured correctly. If anyone has had a similar problem, please let me know what you did to resolve this issue. I have also included the entire error below.
Thanks
************** Exception Text **************
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 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) ---> System.ComponentModel.Win32Exception (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Remove TCP protocol name and port number and try with full hosting website address..something like this
Data Source=www.winhost.com;Initial Catalog=THEDATABASE;
User ID=USERNAME;Password=**;Integrated Security=False;
Eventually I found that the problem was a proxy server. The application is being used by corporations who have proxy servers setup and due to this port 1433 was blocked. I ended up resolving the issue by creating a webservice.

Categories

Resources