Deploy .NET app to Azure using another server database - mysql

Is possible to deploy my .NET application to azure using as connection string another server MySQL database?
I created an application in .NET MVC. It connects to my private server MySQL Database. The application works fine. However, when I deployed it to Azure server, it doesn't working.
When I try to publish, I don't have MySQL as datasource:
When I run it in Azure server, I get the error:
[MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.]
MySql.Data.MySqlClient.NativeDriver.Open() +1228
MySql.Data.MySqlClient.Driver.Open() +22
MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +218
MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +287
MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +93
MySql.Data.MySqlClient.MySqlPool.GetConnection() +65
MySql.Data.MySqlClient.MySqlConnection.Open() +566
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +41
My connectionstring:
<connectionStrings>
<add name="myEntities" connectionString="metadata=res://*/Models.MyModel.csdl|res://*/Models.MyModel.ssdl|res://*/Models.MyModel.msl;provider=MySql.Data.MySqlClient;provider connection string="server=myServer;user id=userName;password=Password;database=myDB"" providerName="System.Data.EntityClient" />
</connectionStrings>
Does anyone know how to fix it?
Thanks

You can certainly connect to a MySQL server from an MVC web app. Your MySQL server can be hosted in Azure, AWS, or any other hosting provider that lets you connect to your database remotely. However, making database calls outside of your Azure data enter will cause a delay due to network latency.

Related

Getting error "A network-related or instance-specific error occurred while establishing a connection to SQL Server" when using MySQL and Authorization

I have an ASP.NET project running on .NET Framework 4.8 and using MySQL for the database. Everything was working fine, till I decided to user Authorization. I have the following:
[Authorize(Roles = "Admin")]
public class ApproveActionsController : DaysOffBaseController
{
}
The moment I try to access the URL: https://myApp/DayOffModule/ApproveActions/ApproveDaysOffList
I'm getting the following error message and the app is throwing 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)
I have read a lot and it looks like it's thinking that it thinks I'm using SQL Server or trying to connect to it. I have tried looking everywhere in the app for System.Data.SqlClient and changed it to MySql.Data.MySqlClient but it's still throwing the same Exception.
When I remove the [Authorize(Roles = "Admin")] from the controller above - I'm not having this issue.
Here is the entire stack:
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.
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server account's credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
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.
Stack Trace:
[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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) +1524
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +706
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +57
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1186
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +315
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +128
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +265
System.Data.SqlClient.SqlConnection.Open() +133
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +82
[HttpException (0x80004005): Unable to connect to SQL Server database.]
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +175
System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +121
System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +57
System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +475

Using an AWS Elastic Load Balancer for MySQL Cluster

I have a web server which connects to a MySQL cluster (it's Galera cluster)... the cluster works fine (if I update a record on the first instance of MySQL, it is automatically updated on the second instance). The problem is I need a load balancer between the web server and MySQL instances...
So What I have done is to setup an AWS Network Load Balancer (NLB works on Network Layer, TCP in my case)... I have added the 2 instances of MySQL to the NLB's Target group (their private IPs).
Now I go ahead an update the connection string in my Web Server to connect to the NLB:
<add name="MyDB" connectionString="Server=my-nlb-ap-southeast-2.amazonaws.com; Port=3306; Database=mydb; Uid=user1; Pwd=mypassword; Protocol=TCP" providerName="MySql.Data.MySqlClient"/>
But I get the following error:
[MySqlException (0x80004005): Unable to connect to any of the
specified MySQL hosts.] MySql.Data.MySqlClient.NativeDriver.Open()
+1734 MySql.Data.MySqlClient.Driver.Open() +60 MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder
settings) +309
MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() +18
MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +290
MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +151
MySql.Data.MySqlClient.MySqlPool.GetConnection() +60
MySql.Data.MySqlClient.MySqlConnection.Open() +1588
MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection
connection) +182
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection
connection)
When I try to connect to MySQL from my web server, I get the following:
This indicates that the web server is able to reach the MySQL instance through the NLB, but I don't know why the connection string is not working.
I have opened all the IPs on port 3306 , and I can connect to MySQL through NLB from my local computer which is not in the VPC:
But the web server connection string is not working...
I am not entirely sure if it's even possible to use an NLB for this purpose?

Login failed for user 'sa' and Pipes Error

I'm getting the following error when trying to log into my system in asp.net (locally and IIS)
Login failed for user 'sa'.
The problem is that in no connection string we are using the SA login to connect to the database (SQL SERVER 2008).
Using the same connection string user and password, I can seamlessly connect to Management Studio ..
<add name="AppConnectionString" connectionString="Data Source=**IPADRESS**;Initial Catalog=**DATABASE**;Persist Security Info=True;User ID=**USER**;Password=**PSW**" providerName="System.Data.SqlClient"/>
An error also appears from time to time, altering with that of SA
No process is on the other end of the pipe
The site was in production for over 3 weeks and we had no problem so far ..
Can it be some IIS configuration, or will it be SQL?

How to sync a remote ASP site with local copy of the site?

I copied an entire ASP site from a remote server to my local machine. I can access the homepage, but once I try to login to the rest of the site, I receive the following 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 set things up to allow for remote connections (enabling TCP/IP and Named Pipes), but is the problem because I'm trying to access a remote database? The connection string in Web.Config is:
<connectionStrings>
<add name="ISBEPI_DEV" connectionString="Data Source=ERI-DB-06\DEVELOPMENT;
Database=ISBEPI_DEV; Initial Catalog=ISBEPI_DEV;Persist Security Info=True;
User ID=Pi_usr; Password =J6$h3Qoz#9Yw;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Any help would be very much appreciated! Please let me know if I can provide more info. Thanks!
Looks like you specified incorrect connection string or you are not allowed to connect to that SQL server. Have you tried to connect to that database from SQL Management Studio or Server Explorer in Visual Studio?

GoDaddy database connectivity error while connecting to MySql database

I am hosting a website on GoDaddy and getting database connectivity error while connecting to MySql database.
The error is coming as "Connection must be valid and open."
This error is coming while establishing the connection itself.
The language used is C# in MVC3.
Database server : MySql
Following is the connection string that I am using to connect to database.
<connectionStrings>
<add name="Application_Database" connectionString="Server=50.62.209.43;Protocol=TCP;Port=3306;Database=#####;Uid=#####;Pwd=######;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Further, I would like to inform that the same connection string (provided above) is working on my local system and other servers also, but it is not working on GoDaddy hosting server.
Please help me out in this issue.