Fatal NServiceBus exception when starting endpoint, cannot open database - c#

We just made some changes to our project and deployed it. We have 7 endpoint databases in our SQL Server database for NServiceBus. We recently added 2 more. One of the two services using one of the two new endpoints fails to start. When looking at our log file we see the following error:
FATAL NServiceBus.GenericHost [(null)] - Exception when starting endpoint.
System.Data.SqlClient.SqlException (0x80131904): Cannot open database "A_NSBEP_WebEventProcessor" requested by the login. The login failed. Login failed for user 'xxxx'
The connection string is
'connection.connection_string'='Data Source=localhost\DevSQLServer;Initial Catalog=A_NSBEP_WebEventProcessor;Integrated Security=true;Enlist=true'
All of the connection strings are configured in OctopusDeploy. They are all identical except obviously for the database name. All of the other services start and login to their respective endpoint with no problem. I even went through the process of creating a .udl file, connecting to the database and using that slightly different connection string. Still without success.
Any thoughts?

Related

Connecting PostgreSQL with ASP.NET MVC using Npgsql

I'm attempting to connect my database to my ASP.NET MVC application but every time I start the application, I get an error saying that my password is incorrect which is impossible. Please let me know if you can see any mistake I've made in my code.
web.config file
Error
The first error it shows is:
System.Data.Entity.Core.ProviderIncompatibleException:
'An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file.
See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.
And the second
PostgresException: 28P01: password authentication failed for user "u173082"
I think your property for the User Id is incorrect. I pulled a functional connection string, which looks like this:
Host=<>;Username=<>;Password=<>;Database=postgres;Port=5432
So, where you have "User Id" in your connection string, try using "Username."

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/

Configuring Umbraco with MySQL: "Could not connect to database"

I am trying to install Umbraco for the first time, and I am using this tutorial. I want to use MySQL instead of MS SQL (which is not shown in the tutorial).
When using the installation wizard, this is the result:
The error logged in UmbracoTraceLog.txt is:
Configured database is reporting as not being available!. Exception: MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> System.Net.Sockets.SocketException (0x80004005): The requested name is valid, but no data of the requested type was found
MySQL is up and running, and I ended up trying the root user just in case it was a permissions issue. I wounder if the table umbraco-cms should already be filled (what would then be the point of the wizard? and where do I find that info?).
I have searched quite a lot about how to install Umbraco using MySQL but I haven't found the necessary info. Other posts indicate that it shouldn't be that difficult.

TransactionScope on Azure App Services with Sql Azure

So I have the following trivial code in a WebAPI controller that is published to an Azure App Service website.
using (var tx = new TransactionScope())
{
var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["OrganizationManagement"].ConnectionString);
connection.Open();
return Enumerable.Empty<TimeSessionDTO>();
}
100% of the time this is giving me a transport error exception on the Open call:
A transport-level error has occurred when receiving results from the
server. (provider: TCP Provider, error: 0 - An existing connection was
forcibly closed by the remote host.)
I have tried using ReliablSqlConnection from the Transient Fault Handling EL block using an exponential retry policy, and I just end up with a transaction timeout with that.
If I remove the surrounding TransactionScope, it works and does not throw an exception.
If I run the same code on my local machine with the connection string still pointing to the SQL Azure database, it works fine with the TransactionScope.
What could be going on that I cannot open a database connection inside of a transaction, in an Azure website?
Update: I should also note that using an Entity Framework DbContext inside of a TransactionScope was working fine. It's just choking on plain ADO.NET for some reason.
FYI I also tried it on a new MVC application on Azure, with the same result. I just don't get it :)
Wow, so the problem seems to have been with the connection string. When I first deployed the database I let the database project build the connection string from the server/database/user info, which I later added to the Web.config file in the WebAPI project. Then when I deployed the WebAPI project I guess it saved that connection string in the publish profile.
It turns out that connection string used a little different format and different options than what is supplied when you view the connection strings in the Azure portal. I had already changed it in the Web.config file, but it seems that what is in the publish profile overwrites what is in Web.config, so the change never took effect on the server.
I guess that explains why it worked when I ran it locally, but I have no idea why it only failed when it was in a transaction.

"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.

Categories