I have created a REST API that tries to connect to a database and execute a SELECT
statement, nothing more. If successful the return String
should be OK otherwise it should return FAIL with some exception details (set within the catch).
Server = "google IP",
Port = 3306,
UserID = "username",
Password = "Your Password",
Database = "database"
It should't be necessary to open up for some IP because the API is on Google App Engine
MySqlConnection connection = new MySqlConnection(connection.connectionstring);
try
{
String query = "select * from tablename";
MySqlCommand command = new MySqlCommand(query, connection);
connection.Open();
command.ExecuteNonQuery();
value = "OK";
connection.Close();
}
catch (Exception ex)
{
value = "FAIL" + ex.Message + ex.Source + ex.InnerException + ex.Data;
}
finally
{
connection.Close();
}
i have tryed nugget: MySql.Data Mysqlconnector
The error outcome i get it this:
Connect Timeout expired.MySqlConnectorSystem.ObjectDisposedException: Safe handle has been closed
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
at Interop.Sys.TryChangeSocketEventRegistration(IntPtr port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data)
at System.Net.Sockets.SocketAsyncContext.Register()
at System.Net.Sockets.SocketAsyncContext.OperationQueue`1.StartAsyncOperation(SocketAsyncContext context, TOperation operation, Int32 observedSequenceNumber)
at System.Net.Sockets.SocketAsyncContext.PerformSyncOperation[TOperation](OperationQueue`1& queue, TOperation operation, Int32 timeout, Int32 observedSequenceNumber)
at System.Net.Sockets.SocketAsyncContext.Connect(Byte[] socketAddress, Int32 socketAddressLen)
at System.Net.Sockets.SocketPal.Connect(SafeCloseSocket handle, Byte[] socketAddress, Int32 socketAddressLen)
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP)
at System.Net.Sockets.TcpClient.Connect(IPAddress address, Int32 port)
at MySqlConnector.Core.ServerSession.OpenTcpSocketAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 775System.Collections.ListDictionaryInternal