ISSUE
While trying to connect to maria db using mysql.data i get this error:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Diagnostics.TraceInternal.get_AppName () [0x0000e] in <e804fc8285a9419784599893ed028695>:0
at System.Diagnostics.TraceInternal.TraceEvent (System.Diagnostics.TraceEventType eventType, System.Int32 id, System.String format, System.Object[] args) [0x0003d] in <e804fc8285a9419784599893ed028695>:0
at System.Diagnostics.Trace.TraceError (System.String message) [0x00000] in <e804fc8285a9419784599893ed028695>:0
at MySql.Data.MySqlClient.MySqlTrace.LogError (System.Int32 id, System.String msg) [0x00026] in <89b4d3936e0b4e49b8d299ddbfe7933d>:0
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x0002e] in <89b4d3936e0b4e49b8d299ddbfe7933d>:0
at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x0001c] in <89b4d3936e0b4e49b8d299ddbfe7933d>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00245] in <89b4d3936e0b4e49b8d299ddbfe7933d>:0
at MyResource.Server.ServerMain..ctor () [0x00026] in C:\Users\Maurice\CFX\MyResource\Server\ServerMain.cs:23
Done.
The .dll file was compiled with dotnet build under debian 10 without warnings or errors
TRIED:
I want to connect to sql Database (MariaDB) via C# and MySql.Data from Oracle.
First I created a folder with the C# script and the .dll's of the MySql.Data package.
After that i added the reference to the .proj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>portable</DebugType>
<TargetName>ServerMain.net</TargetName>
<DefineConstants>SERVER</DefineConstants>
<AssemblyName>TEST.Server.net</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Reference Include="MySql.Data">
<HintPath>MySql.Data.DLL</HintPath>
</Reference>
</ItemGroup>
</Project>
To build the project i used the Visual Studio Code SSH Connection to run in vsc Terminal: dotnet build.
RESULT:
Succesfully started Script with test output but after SQL Connection Open() the Error as seen above was thrown.
MY CODE:
using System;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace TEST.Server
{
public class ServerMain : BaseScript
{
public static void DBTEST()
{
var connString = "server=localhost;user=NAME;database=NAME;port=3306;password=*****";
MySqlConnection conn = new MySqlConnection(connString);
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
public ServerMain()
{
DBTEST();
}
}
}