Я создал REST API, который пытается подключиться к базе данных и выполнить оператор SELECT
, ничего более.В случае успеха возврат String
должен составлять OK , в противном случае он должен возвращать FAIL с некоторыми подробностями об исключении (установленном в пределах улова).
Server = "google IP",
Port = 3306,
UserID = "username",
Password = "Your Password",
Database = "database"
Он должен 'Не нужно открывать какой-то IP, потому что API на 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();
}
Я попробовал самородок: MySql.Data Mysqlconnector
В результате ошибки я получаю это:
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