Cannot connect remote server to smartfox with unity3d - c#

I'm trying to connect smartfoxserver with unity3d. local machine is working fine. But when I've tried on my server ip like xx.xx.xx.xx, given error like follow,
What should I do?
Http error creating http connection: System.Net.Sockets.SocketException: Connection refused
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] in <filename unknown>:0
UnityEngine.Debug:Log(Object)
SFS2X_Connect:OnConnection(BaseEvent) (at Assets/SFS2X_Connect.cs:31)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
SFS2X_Connect:Update() (at Assets/SFS2X_Connect.cs:37)
connection code is shown below
public class SFS2X_Connect : MonoBehaviour {
public string ServerIP = "xxx.xxx.xxx.xxx";
public int ServerPort = 9933;
SmartFox sfs;
void Start () {
sfs = new SmartFox ();
sfs.ThreadSafeMode = true;
sfs.AddEventListener (SFSEvent.CONNECTION, OnConnection);
sfs.Connect (ServerIP, ServerPort);
}
void OnConnection(BaseEvent evt)
{
if ((bool)evt.Params ["success"]) {
Debug.Log ("Successfully Connected");
}
else {
Debug.Log ((string)evt.Params["errorMessage"]);
}
}
void Update () {
sfs.ProcessEvents();
}
}

Create a ConfigData then pass it to sfs for connection :
ConfigData cfg = new ConfigData();
cfg.Host = "x.x.x.x";
cfg.Port = 9932;
cfg.Zone = loginZone;
cfg.Debug = true;
smartFox.Connect(cfg);

Related

Sporadic failure of System.Net.FtpClient.FileExists

I am trying to move to using System.Net.FtpClient, but things are not working as expected.
Running the code below, it seems like even though IsConnected returns true, a directly following call to FileExists() calls Connect() (which means the connection is lost exactly between the calls?). However, as Connect() can fail every now and then, this also results in a failing FileExists() (where failing means it throws Connection refused).
Is there anything wrong with my code? Is this something to be expected, i.e. should I be prepared to retry everything I do with an FtpClient instance? Is there any flag to set to retry automatically?
string myPath = ..;
string myTempPath = myPath+".tmp";
_client = GetClient(_ioc, false);
var _stream = _client.OpenWrite(myTempPath);
//write to stream
_stream.Close();
Android.Util.Log.Debug("NETFTP", "connected: " + _client.IsConnected.ToString()); //always outputs true
if (_client.FileExists(myPath) //sporadically throws, see below
_client.DeleteFile(myPath);
where GetClient() is implemented as using my custom "retry-loop" to hande sporadic connecting failures.
private static T DoInRetryLoop<T>(Func<T> func)
{
double timeout = 30.0;
double timePerRequest = 1.0;
var startTime = DateTime.Now;
while (true)
{
var attemptStartTime = DateTime.Now;
try
{
return func();
}
catch (System.Net.Sockets.SocketException e)
{
if ((e.ErrorCode != 10061) || (DateTime.Now > startTime.AddSeconds(timeout)))
{
throw;
}
double secondsSinceAttemptStart = (DateTime.Now - attemptStartTime).TotalSeconds;
if (secondsSinceAttemptStart < timePerRequest)
{
Thread.Sleep(TimeSpan.FromSeconds(timePerRequest - secondsSinceAttemptStart));
}
}
}
}
internal FtpClient GetClient(IOConnectionInfo ioc)
{
FtpClient client = new FtpClient();
if ((ioc.UserName.Length > 0) || (ioc.Password.Length > 0))
client.Credentials = new NetworkCredential(ioc.UserName, ioc.Password);
else
client.Credentials = new NetworkCredential("anonymous", "");
Uri uri = IocPathToUri(ioc.Path);
client.Host = uri.Host;
if (!uri.IsDefaultPort)
client.Port = uri.Port;
client.EnableThreadSafeDataConnections = false;
client.EncryptionMode = ConnectionSettings.FromIoc(ioc).EncryptionMode;
Func<FtpClient> connect = () =>
{
client.Connect();
return client;
};
return DoInRetryLoop(connect);
}
This is the exception which appears sporadically:
System.Net.Sockets.SocketException : Connection refused
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00017] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs:127
at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00017] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs:127
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.Sockets.Socket.EndConnect (IAsyncResult result) [0x0002f] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1593
at System.Net.Sockets.Socket.EndConnect (IAsyncResult result) [0x0002f] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1593
at System.Net.FtpClient.FtpSocketStream.Connect (System.String host, Int32 port, FtpIpVersion ipVersions) [0x0011a] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpSocketStream.cs:611
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpSocketStream.Connect (System.String host, Int32 port, FtpIpVersion ipVersions) [0x0011a] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpSocketStream.cs:611
10-24 13:08:07.487 I/mono-stdout(24073): at (wrapper remoting-invoke-with-check) System.Net.FtpClient.FtpSocketStream:Connect (string,int,System.Net.FtpClient.FtpIpVersion)
at (wrapper remoting-invoke-with-check) System.Net.FtpClient.FtpSocketStream:Connect (string,int,System.Net.FtpClient.FtpIpVersion)
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.Connect () [0x000ce] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:807
at System.Net.FtpClient.FtpClient.Connect () [0x000ce] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:807
at System.Net.FtpClient.FtpClient.Execute (System.String command) [0x00136] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:735
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.Execute (System.String command) [0x00136] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:735
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.Execute (System.String command, System.Object[] args) [0x00001] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:694
at System.Net.FtpClient.FtpClient.Execute (System.String command, System.Object[] args) [0x00001] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:694
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.DirectoryExists (System.String path) [0x0005d] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2679
at System.Net.FtpClient.FtpClient.DirectoryExists (System.String path) [0x0005d] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2679
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.FileExists (System.String path, FtpListOption options) [0x0001c] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2751
10-24 13:08:07.487 I/mono-stdout(24073): at System.Net.FtpClient.FtpClient.FileExists (System.String path) [0x00001] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2733
at System.Net.FtpClient.FtpClient.FileExists (System.String path, FtpListOption options) [0x0001c] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2751
at System.Net.FtpClient.FtpClient.FileExists (System.String path) [0x00001] in [my source folder]src
etftpandroid\System.Net.FtpClient\FtpClient.cs:2733
It turned out that the FtpClient was reconnecting due to some unexpected response from the client which triggered the reconnect because of "stale data". My solution was to derive my own class from FtpClient which overrides the Connect() method using the DoInRetryLoop as posted in the question.
Unfortunately, this only works with either EnableThreadSafeDataConnections=false or with overriding the "CloneConnection" method as well. The latter required me to make it virtual.

How to I catch SSL exceptions in a Mono HTTPListener server?

I'm trying to add HTTPS support to my simple Mono HTTP server. It works perfectly most of the time, but the application crashes when an SSL exception occurs, such as the client canceling the handshake. Obviously something like that shouldn't completely crash it, so I need to catch that exception somehow.
Code:
static void Main(string[] args)
{
try
{
var listener = new HttpListener();
string prefix = "https://*:8443/";
listener.Prefixes.Add(prefix);
Console.WriteLine("Starting HTTP server at " + prefix);
listener.Start();
while (true)
{
try
{
var context = listener.GetContext();
Console.WriteLine(context.Request.Url);
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Exception processing request: " + e);
Console.ResetColor();
}
}
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Exception caught! " + e);
}
}
Here's the log when I get a wonky client trying to connect:
Starting HTTP server at https://*:8443/
Unhandled Exception:
System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The client stopped the handshake.
at Mono.Security.Protocol.Tls.SslServerStream.EndNegotiateHandshake (IAsyncResult asyncResult) <0x41e581b0 + 0x0022b> in <filename unknown>:0
at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult) <0x41e57d20 + 0x00086> in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Security.Protocol.Tls.SslStreamBase.EndRead (IAsyncResult asyncResult) <0x41e50110 + 0x0015f> in <filename unknown>:0
at Mono.Net.Security.Private.LegacySslStream.EndAuthenticateAsServer (IAsyncResult asyncResult) <0x41e50000 + 0x0003e> in <filename unknown>:0
at Mono.Net.Security.Private.LegacySslStream.AuthenticateAsServer (System.Security.Cryptography.X509Certificates.X509Certificate serverCertificate, Boolean clientCertificateRequired, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation) <0x41e40990 + 0x00055> in <filename unknown>:0
at System.Net.HttpConnection.Init () <0x41e3e0e0 + 0x0005f> in <filename unknown>:0
at System.Net.HttpConnection..ctor (System.Net.Sockets.Socket sock, System.Net.EndPointListener epl, Boolean secure, System.Security.Cryptography.X509Certificates.X509Certificate cert) <0x41e3b670 + 0x003e7> in <filename unknown>:0
at System.Net.EndPointListener.OnAccept (System.Object sender, System.EventArgs e) <0x41e3b210 + 0x002a7> in <filename unknown>:0
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) <0x41e3b1d0 + 0x0002e> in <filename unknown>:0
at System.Net.Sockets.SocketAsyncEventArgs.Complete () <0x41e3b1b0 + 0x00013> in <filename unknown>:0
at System.Net.Sockets.Socket.<AcceptAsyncCallback>m__0 (IAsyncResult ares) <0x41e3aa70 + 0x0037f> in <filename unknown>:0
at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) <0x41e3a980 + 0x0001d> in <filename unknown>:0
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () <0x7f22cac25460 + 0x0002f> in <filename unknown>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () <0x7f22cac239e0 + 0x001d6> in <filename unknown>:0
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x7f22cac252e0 + 0x00008> in <filename unknown>:0
Not quite a solution, but I was able to work around the problem by creating a local reverse proxy with nginx, and setting the mono server to only listen on 127.0.0.1
https://www.nginx.com/resources/admin-guide/reverse-proxy/

mono c# strange Address already in use error

Its my first time using mono, I have compiled some ready code and tried to use on my linux host yet i get strange error. I am not really experienced with C# like experts but i can manage code.
I forgot to mention, there isnt any single app using port 5031. I even changed port to random numbers yet it still gives same error.
Unhandled Exception:
System.Net.Sockets.SocketException: Address already in use
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start (Int32 backlog) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.NetTcp.TcpChannelListener`1[System.ServiceModel.Channels.IDuplexSessionChannel].OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.ListenerLoopManager.Setup (TimeSpan openTimeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.ServiceHostBase.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open () [0x00000] in <filename unknown>:0
at H_Auth.AuthSvc.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: Address already in use
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start (Int32 backlog) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start () [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.NetTcp.TcpChannelListener`1[System.ServiceModel.Channels.IDuplexSessionChannel].OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.ListenerLoopManager.Setup (TimeSpan openTimeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.ServiceHostBase.OnOpen (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00000] in <filename unknown>:0
at System.ServiceModel.Channels.CommunicationObject.Open () [0x00000] in <filename unknown>:0
at H_Auth.AuthSvc.Main (System.String[] args) [0x00000] in <filename unknown>:0
and this is my code
namespace H_Auth
{
internal class AuthSvc
{
private static void Main(string[] args)
{
var adrs = new Uri[1];
adrs[0] = new Uri("net.tcp://localhost:5031/");
using (ServiceHost serviceHost = new ServiceHost(typeof (HBChannel), adrs))
{
try
{
serviceHost.AddServiceEndpoint(typeof (IA), (System.ServiceModel.Channels.Binding) new NetTcpBinding(SecurityMode.None), "Auth.svc");
ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
serviceHost.Description.Behaviors.Add((IServiceBehavior) metadataBehavior);
((ServiceHostBase) serviceHost).AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
serviceHost.Open();
string str = Regex.Match(((AssemblyFileVersionAttribute) Assembly.GetEntryAssembly().GetCustomAttributes(typeof (AssemblyFileVersionAttribute), false)[0]).Version, "^\\d+\\.\\d+").Value;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Revision " + str + "\r\n");
Console.ResetColor();
Console.WriteLine("press \"S\" for stats print");
Console.WriteLine();
ConsoleKeyInfo consoleKeyInfo = new ConsoleKeyInfo();
while (consoleKeyInfo.Key != ConsoleKey.Enter)
{
consoleKeyInfo = Console.ReadKey(true);
if (consoleKeyInfo.Key == ConsoleKey.S)
{
AuthImpl.Instance.RemoveExpiredSessions();
AuthSvc.PrintStats(AuthImpl.Instance.GetSessions);
}
}
serviceHost.Close();
}
catch (CommunicationException ex)
{
Logging.Ex(ex.Message);
serviceHost.Abort();
}
}
Console.ReadLine();
}
private static void PrintStats(List<SessInfo> Sessions)
{
Console.WriteLine("Current active sessions:");
Dictionary<string, int> dictionary1 = new Dictionary<string, int>();
foreach (SessInfo sessInfo in Sessions)
{
if (!dictionary1.ContainsKey(sessInfo.BotSignature))
{
dictionary1.Add(sessInfo.BotSignature, 1);
}
else
{
Dictionary<string, int> dictionary2;
string botSignature;
(dictionary2 = dictionary1)[botSignature = sessInfo.BotSignature] = dictionary2[botSignature] + 1;
}
}
if (dictionary1.Count > 0)
{
foreach (KeyValuePair<string, int> keyValuePair in dictionary1)
Console.WriteLine(string.Format("'{0}': {1} user {2}", (object) keyValuePair.Key, (object) keyValuePair.Value, keyValuePair.Value > 1 ? (object) "S" : (object) ""));
}
else
Console.WriteLine("There is no active sessions");
}
}
}
I had the same problem and I've figured it out.
My problem (and maybe yours) was that I was using the same base port for different endpoints.
Notice that, it works for Windows, but not for Linux:
var host = new ServiceHost(typeof(MyService), new Uri("net.tcp://localhost:10500/UCB"));
host.AddServiceEndpoint(typeof(IService1), CreateTcpBinding(), "IService1");
host.AddServiceEndpoint(typeof(IService2), CreateTcpBinding(), "IService2");
This will create the following:
net.tcp://localhost:10500/UCB/IService1
net.tcp://localhost:10500/UCB/IService2
It works on Windows, but not on Linux, something to do with port-sharing.
In order to work on Linux, we need to have different ports, like:
net.tcp://localhost:10500/UCB/IService1
net.tcp://localhost:10501/UCB/IService2
Working code:
var host = new ServiceHost(typeof(MyService), new Uri("net.tcp://localhost"));
host.AddServiceEndpoint(typeof(IService1), CreateTcpBinding(), "net.tcp://localhost:10500/UCB/IService1");
host.AddServiceEndpoint(typeof(IService2), CreateTcpBinding(), "net.tcp://localhost:10501/UCB/IService2");

WebClient: (System.Net.WebException) Error getting response stream (ReadDone1): ReceiveFailure

This is a MonoTouch application. I see errors out in the field with this exception. I see other SO quesitons, but nothing seems to be solving my issue. Could this be related to maxRequestLength on the server, or executionTimeout? I really have NO ideas...
I am not using a WebRequest, i'm using a WebClient. Please Help!
STACK TRACE
System.Net.WebException: Error getting response stream (ReadDone1): ReceiveFailure
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in <filename unknown>:0
at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.UploadFileCore (System.Uri address, System.String method, System.String fileName, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.UploadFile (System.Uri address, System.String method, System.String fileName) [0x00000] in <filename unknown>:0
Client Code (Monotouch)
public void UploadVideo(Guid organizationId, string path) {
WebClient wc = new WebClient();
var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password)));
var authHeader = string.Format("Basic {0}", token);
wc.Headers.Add("Authorization", authHeader);
var resource = string.Format("/organizations/{0}/SyncVideo/", organizationId);
var fi = new FileInfo(path);
wc.UploadFile(restClient.BaseUrl + resource, "POST", path);
wc.Dispose();
}
Server Code (ASP.Net MVC3)
[HttpPost, Url("v3/organizations/{organizationId?}/SyncVideo/")]
public virtual JsonResult SyncVideo(HttpPostedFileBase file, Guid? organizationId) {
if (organizationId.IsNull()) throw new HttpNotFoundExecption();
if (organizationId != RESTContext.OrganizationId) throw new HttpNotAuthorizedException();
var basePath = RESTContext.Config.VideoPath;
using (new Impersonator(RESTContext.Config.VideoPathUsername, RESTContext.Config.VideoPathDomain,
RESTContext.Config.VideoPathPassword)) {
if (!Directory.Exists(basePath))
Directory.CreateDirectory(basePath);
file.SaveAs(basePath + #"\" + file.FileName);
}
return JsonSuccess();
}

Mono on Ubuntu MySqlConnection.Open resulting in System.OverflowException

I am trying to get the demo from http://www.mono-project.com/MySQL working on Ubuntu 11.10, using Mono 2.10.5.
Installed MySQL v2 drivers (after renaming) to the gac. Added provider a line to the machine.config.
Hello World demo compiles and runs fine. The following code executes and connects on MSVS fine.
The compile cmd works: mcs TestMysqlConnect.cs -r:System.Data.dll -r:/home/steve/MONO/Assemblies/Mysql/v2/MySql.Data.dll
using System;
using System.Data;
using MySql.Data.MySqlClient;
public class Test
{
public static void Main(string[] args)
{
string connectionString =
"Server=192.168.111.4;" +
"Database=LOADTRACKER;" +
"Port=3306;" +
"User ID=oec;" +
"Password=oec;" +
"Pooling=false";
Console.WriteLine("Create MySqlConnection");
IDbConnection dbcon;
dbcon = new MySqlConnection(connectionString);
Console.WriteLine("dbcon.Open();");
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
Console.WriteLine("dbcon.CreateCommand();");
// requires a table to be created named employee
// with columns firstname and lastname
// such as,
// CREATE TABLE employee (
// firstname varchar(32),
// lastname varchar(32));
string sql =
"SELECT Account, Security " +
"FROM accesslist";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string acct = (string) reader["Account"];
string sec = (string) reader["Security"];
Console.WriteLine("Acct: " + acct + " (" + sec + ")");
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
Executing this code produces:
$mono ./TestMysqlConnect.exe
Create MySqlConnection
dbcon.Open();
Unhandled Exception: System.OverflowException: Number overflow.
at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.HandleAuthChange (MySql.Data.MySqlClient.MySqlPacket packet) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate (Boolean reset) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.String authMethod, Boolean reset) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.Open () [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Driver.Open () [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Number overflow.
at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.HandleAuthChange (MySql.Data.MySqlClient.MySqlPacket packet) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate (Boolean reset) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.Authenticate (System.String authMethod, Boolean reset) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.Open () [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Driver.Open () [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0
Interestingly, if I provide a bad user/password, I get the expected exception of:
[ERROR] FATAL UNHANDLED EXCEPTION: MySql.Data.MySqlClient.MySqlException: Authentication to host '192.168.111.4' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'#'linux' (using password: YES) ---> MySql.Data.MySqlClient.MySqlException: Access denied for user 'root'#'linux' (using password: YES)
Any help is greatly appreciated. Thank you.

Categories