What else I should do to connect to MySql Server on AWS EC2 from VS2017 on my local computer?

0

I am developing an asp.net core 2.1 application with MySql.

While running this application by pressing F5, I am unable to connect to MySql server on EC2 on AWS with connection string to below:
string connStr = "server= ec2-xx-x-xxx-xxx.compute-1.amazonaws.com;user=user1;port=3306;database=world;password= mypassword; SslMode=none; default command timeout=120"; I get this error:

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at etc. etc.

But I am able to connect to MySql server on my local machine with connection string below:

string connStr = "server=localhost;user= user1;port=3306;database=world;password=mypassword; SslMode=none; default command timeout=120";

If I publish this web app at aws ec2 where MySql is installed, with the above connection sring (server=localhost), the application runs fine.

In MySql On EC2 (which is Ubuntu 18.04 server)

• I have created user1 for MySql with host as ‘ %’ so that it could connect from any where.

• I granted all previliges to user1 to connect from my IP address with query
GRANT ALL PRIVILEGES ON . TO user1@'1x2.1xx.8x.2xx'

• I checked privileges for user1 with query SHOW GRANTS FOR 'user1'@'%' and I get following results

'GRANT ALL PRIVILEGES ON . TO \'user1\'@\'%\' WITH GRANT OPTION'
'GRANT ALL PRIVILEGES ON world.* TO \'user1\'@\'%\''

• In configuration file of MySql I set binding to 0.0.0.0 so it accept remote connection from anywhere.

• In My security group for EC2 I have opened port 3306 to accept connection from my IP address.

After increasing timeout period to 30 second the error is:

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> System.AggregateException: One or more errors occurred. (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 xx.x.xxx.xxx:3306) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: 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 xx.x.xxx.xxx:3306 at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context) --- End of stack trace from previous location where exception was thrown --- at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context) at System.Net.Sockets.Socket.MultipleAddressConnectCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult) at System.Net.Sockets.TcpClient.<>c.b__28_1(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at etc.etc.

What else I should do to connect to MySql Server on AWS EC2 from VS2017 on my local computer?

mysql
visual-studio-2017
asked on Stack Overflow Jul 6, 2018 by Zeni • edited Jul 7, 2018 by Zeni

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0