IIS can't get access to database of context - c#

I have some troubles with IIS client. I mean, when I use tests or just connect in my DB in MSSMS everything is fine. But when I open my site I get the error:
provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred.
** - for secure ofc.
Connection string what I found when I debug code:
Data Source=(LocalDB)\MSSQLLocalDB;integrated security=false;Initial Catalog=**;User ID=**;Password=**;Connection Timeout=60;MultipleActiveResultSets=True;Max Pool Size=1024
Maybe someone can help me, idk how I should fix that because that is rly strange bug. I mean... all tests works ( they have same connections string)

Related

Random unable to connect from Azure to On-Premise MySql

We are using different services in the Azure Cloud (App services / function apps) to connect to a On-Premise MySql database on Ubuntu. This works the most time very well, but sometimes and totally random we received the following error.
Detail:
The connection works most time great and everything seems correct configured. Only sometimes e.g. every 27th request runs into an error. I assume the received error message is maybe wrong.
Example extract from our log:
2018-02-21 15:53:55.647 +00:00 [Error] Microsoft.EntityFrameworkCore.Database.Connection: An error occurred using the connection to database 'XXXXXXX' on server 'XXX.XXX.XXX.XXX'.
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
at MySqlConnector.Core.ServerSession.<ConnectAsync>d__56.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 212
We are connecting to this database from different sites, but this error only appears from the Azure Cloud.
We double-checked the connection string, firewall settings and outgoing IPs several times.
Connection String:
Persist Security Info=True;server=xxx.xxx.xxx.xxx;database=xxxxxx;uid=xxxxx;password=xxxxx;port=3306;
On some days we doesn’t received this error, but on the other day many times per day and totally random. It would be great to get help from you to identify the problem and solve it soon. Thanks a lot!
It is hard to help without a code example.
You can only check the common things:
- connection string correct order
"Server=TheServerAddress; Port=YourPortNumber; Database=YourDatabase; Uid=YourUsername; Pwd=YourPassword;"
- add default port. Ex.: 3306 to connection string
- check the query code async or not and if its the same in other application
Also you can try a retry:
https://blogs.msdn.microsoft.com/bartr/2010/06/20/sql-azure-connection-retry-update/
http://peterkellner.net/2011/01/21/sqlazure-connection-retry-problem-using-best-practices/

Debugging MySQL connection issues from C# application

I seem to be missing something obvious, and it's been bothering me for last few days.
I use a C# application on Windows Server 2012 to connect to MySQL database to generate a report end of the day. I use Task Scheduler to run this application.
While it seems to be running smoothly when I run manually - When the I run the application at a set time (11pm) - it throws MySQL connection error, i.e. Unable to connect to localhost (I email myself the error).
This has happened a few times, and I am unable to recreate the issue.
How can I troubleshoot/debug this -? I've looked into Windows Events and can't find anything. Where would MySQL connection issues be logged?
Then Connection string on App.Config
<add name="strConnectionString" connectionString="Database='myproject';user id='root';password='password'; Server='localhost'" providerName="MySql.Data.MySqlClient"/>
Thanks in Advance.
Changed "localhost" to 127.0.0.1 in the connection string seems to have done the trick. I don't know why however.

Error 26: Error Locating Server/Instance Specified in production environment - SQL server 2014 wpf wcf

I realise that this problem has been raised many times and a number of suggestions for how to fix it have been made, but despite following many of these suggestions, including all the one's listed here: How to solve Error 26: Error Locating Server/Instance Specified in production environment?
and here: http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
and turning the firewall off I still can't resolve my problem. I have a WCF service that I am running via Visual Studio Express 2012 for Web. The service talks to a database I have set up in SQL Server Management studio. The server, database and service are all running locally on a windows 8 laptop. I connect the to service via a WPF application on the same laptop. This is a development version hence running it all on the laptop. This works fine on one laptop but when I transfer everything over to another laptop I get the error: 26 issue. Both laptops are the same (same make/model/spec/OS).
The machine that works has the following connection string (where laptop-name is the name of my laptop and DBname is the name of the database):
<add name="AirportTaxiAccountsPackageDBConnectionString" connectionString="Data Source=laptop-name\SQLEXPRESS;Initial Catalog=DBname;Integrated Security=True"
providerName="System.Data.SqlClient" />
NB:the set up details within SQL server management studio are: server name is laptop-name\SQLEXPRESS and the connection is laptop-name\user-nameA
The machine that doesn't work has the following connection string:
<add name="AirportTaxiAccountsPackageDBConnectionString" connectionString="Data Source=laptop-name\SQLEXPRESS;Initial Catalog=DBname;Integrated Security=True"
providerName="System.Data.SqlClient" />
NB: the set up details within SQL server management studio on this computer are: server-name is laptop-name\SQLEXPRESS and the connection is laptop-name\user-nameB
This connection string was set up on the second laptop by creating and testing the connection from within VS via the database connection wizard. when I test the connection via the wizard it works fine, it's only when I connect to it via my wpf application that a connection problem occurs.
One last thing, I checked the service is runnning correctly on the second laptop, it is fine and I can connect to it, the problem occurs when I try to access the database. the process is run service using host, connect to service via WPF, connect to database > error 26
Any ideas?
Edited again
i've set up a test client which can access the service, I get the same error which is the error 26 error locating server/instance specified
RESOLVED
I was hard coding the database configuration details again via a class within the service rather than talking to the configuration file!! I am a dufus but now I know better :)
I had hard coded the database connection string into configuration class within the service which was overwriting the database connection string in the app.config file blush

"Can not find server or is not available" on test server but not while debugging

I keep getting an error when trying to access the database from a web site it returns an error that it can't find the server or it's inaccessible.
Now I did a search and I found many possible reasons - I turned on named pipes and also did what this link suggested (i.e. set the IP addresses to "enabled") yet I'm still getting the error.
Error SqlException: System.Data.SqlClient.SqlException (0x80131904):
Error An error has occurred with the network or the occurrence when
connecting to SQL Server. Can not find server or is not available.
Verify that the instance name is correct and that the configuration of
SQL Server allow remote connections. (provider: Named Pipes Provider,
error: 40 - Could not open a connection to SQL Server) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection) at
I also downloaded this little app and I copy/pasted the connection string from the web.config used in IIS for this site and the app is able to connect and query the same database being targeted by the web site.
And, as the title says, this error is utterly missing when I debug it in VS2010. What could be causing this error when launching from the server?
Edit: the connection string includes a user name and password (it's not Windows Authentication).
Most likely a security issue. If using windows authentication then make sure the thread pool that the web application is running as has sufficient DB access\privileges.
The issue is that the web.config references another config file
<appSettings file="config/dev.config">
and so the connection string in web.config is ignored over the one in dev.config - an error to have it in both (the one on the test server was created by someone else and worked on static pages - it only failed when the website had to query the database), that's why the version in Visual Studio was running fine.

SQL Server connectivity issues even with valid connection string

This has been plaguing me for the last few hours, I'm recieving the following error message on an ASP.NET web page:
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)
In the past to fix this I've found it was a simple connection string error, however I'm using Idera's Connection String generator tool. It seems to be able to connect to the server just fine when I test the string. I can connect with SQL Management Studio, as well as I can create a blank .udl file, fill in the details, and it connects without issue.
I've double checked, and the server is allowing remote connections, I turned the firewall off at this point (just trying to get this to work) and still no go.
Do you guys think I'm missing something ? Any help is GREATLY appreciated!
And when you try adding a connection from Visual Studio ?
You could also use the connection string that is generated by VS while doing this.
It seems as if you are missing the instance name or something like that.
Edit : Yes, as explained in the comment : Right click the connection, then copy the Connection string.
But you might have to replace the "name" by the IP address, if the resolution of the host name is not being performed correctly
From the web servercan you resolve the name of the server using in the connection string - i.e. is it a DNS issue?

Categories