title: Problem with mysql connection to local MariaDB MySQL Linux server via localhost/127.0.0.1 in c# mono app
body: <p>I made a plugin to collect data from the players on my SCP:SL (game) server and saving it to MySQL database.</p>
  
  <p>When connect to external databases, located outside my local VPS(like freemysqlhosting), it works perfectly.</p>
  
  <p>My local VPS is running <code>10.1.37-MariaDB-0+deb9u1 Debian 9.6 MySQL Server</code> with the newest mono version.</p>
  
  <p>The problem starts when I am trying to connect to my MariaDB Linux MySQL database locally (via localhost/127.0.0.1).
  When it comes to connect to the database, I am getting two different errors:</p>
  
  <ul>
  <li>one for localhost(the app isn't crashing),</li>
  <li>one for 127.0.0.1(the app is crashing)</li>
  </ul>
  
  <p>I am getting this error, when host is specified as "localhost"</p>
  
  <pre><code>Unhandled Exception:
  MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---&gt; System.AggregateException: One or more errors occurred. ---&gt; System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used
    at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00014] in &lt;ac210d81537245bc838518cc8e845861&gt;:0 
    at System.Net.Sockets.Socket.EndConnect (System.IAsyncResult asyncResult) [0x0002c] in &lt;ac210d81537245bc838518cc8e845861&gt;:0 
    at System.Net.Sockets.TcpClient.EndConnect (System.IAsyncResult asyncResult) [0x0000c] in &lt;ac210d81537245bc838518cc8e845861&gt;:0 
    at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
     --- End of inner exception stack trace ---
    at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
    at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) [0x00043] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
    at System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout) [0x00000] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
    at MySql.Data.Common.StreamCreator.GetTcpStream (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x0001f] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.Common.StreamCreator.GetStream (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00021] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.MySqlClient.NativeDriver.Open () [0x00007] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
  ---&gt; (Inner Exception #0) System.Net.Sockets.SocketException (0x80004005): An address incompatible with the requested protocol was used
    at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00014] in &lt;ac210d81537245bc838518cc8e845861&gt;:0 
    at System.Net.Sockets.Socket.EndConnect (System.IAsyncResult asyncResult) [0x0002c] in &lt;ac210d81537245bc838518cc8e845861&gt;:0 
    at System.Net.Sockets.TcpClient.EndConnect (System.IAsyncResult asyncResult) [0x0000c] in &lt;ac210d81537245bc838518cc8e845861&gt;:0 
    at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 &lt;---
  
    at MySql.Data.MySqlClient.NativeDriver.Open () [0x00041] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.MySqlClient.Driver.Open () [0x0000e] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x0004e] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection () [0x00006] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection () [0x0008a] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x0003f] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x0001c] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0016d] in &lt;ffa6b95770be4daf8d8ae25ca059b16a&gt;:0 
    at DataCollector.RoundEventHandler.&lt;OnWaitingForPlayers&gt;g__CheckIfTableExists|3_0 () [0x000db] in &lt;8dda65d2174e4f2a8af95550bb525546&gt;:0 
    at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
    at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
    at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
    at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
    at System.Threading.ThreadHelper.ThreadStart () [0x00008] in &lt;f2e6809acb14476a81f399aeb800f8f2&gt;:0 
  </code></pre>
  
  <p>The error, when I am specifying host as "127.0.0.1" looks like that (it is so long so i attach a pastebin of it)</p>
  
  <p><a href="https://pastebin.com/Xf1hn3in" rel="nofollow noreferrer">https://pastebin.com/Xf1hn3in</a></p>
  
  <p>This is the c# mysql connection code for my plugin, I am using MySQLConnector v 8.0.13 to connect to the database:</p>
  
  <pre><code>                MySqlConnectionStringBuilder connstr = new MySqlConnectionStringBuilder();
                  DatabaseConnInfo.dbhost = _plugin.GetConfigString("dc_dbhost");
                  DatabaseConnInfo.dbname = _plugin.GetConfigString("dc_dbname");
                  DatabaseConnInfo.dbuser = _plugin.GetConfigString("dc_dbuser");
                  DatabaseConnInfo.dbpass = _plugin.GetConfigString("dc_dbpass");
                  DatabaseConnInfo.dbport = (uint)_plugin.GetConfigInt("dc_dbport");
  
                  connstr.Server = DatabaseConnInfo.dbhost;
                  connstr.Database = DatabaseConnInfo.dbname;
                  connstr.UserID = DatabaseConnInfo.dbuser;
                  connstr.Password = DatabaseConnInfo.dbpass;
                  connstr.Port = DatabaseConnInfo.dbport;
                  _plugin.Info(connstr.ToString());
                  MySqlConnection conn = new MySqlConnection(connstr.ToString());
                  conn.Open();
                  string sql = "some sql statement";
                  MySqlCommand comm = new MySqlCommand(sql, conn);
                  conn.Close();
  </code></pre>
  
  <p>The expected result is to have a working connection to the local database, which is not working due to the errors.</p>
  
  <p>Those errors are weird, because I can connect to the external databases with ease, the local connection seems to be a problem, and I do not know what to do.</p>