once again im not really getting any further by just using google and searching through the forum, so here we go:
Im trying to establish a connection with C# and a MySQL Database (which is running on phpmyadmin).
This is the Code I got so far:
using System;
using System.Data;
using MySql.Data.MySqlClient;
using MySql.Data;
namespace csharpdatabasefinal
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("C#: Connect to MySQL Database using localhost." + Environment.NewLine);
string connectionString = "server=localhost;user=csharptest;database=csharptest;port=3306;password=123";
MySqlConnection conn = new MySqlConnection(connectionString);
try
{
conn.Open();
Console.WriteLine("Connection is " + conn.State.ToString() + Environment.NewLine);
conn.Close();
Console.WriteLine("Connection is " + conn.State.ToString() + Environment.NewLine);
}catch(MySql.Data.MySqlClient.MySqlException ex)
{
Console.WriteLine("Error: " + ex.Message.ToString());
}
Console.WriteLine("Press any key to exit..");
Console.Read();
}
}
}
And this is the Error I get, I guess it has something to do with the References but im not really sure.. I added as reference "MySql.Data.dll" & "System.Security.Permissions.dll". I added the Systen.Security.Permission.dll because in a previous error he asked for it.
And this is the Error I get:
Here the full Error Code:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
Source=MySql.Data
StackTrace:
at MySql.Data.MySqlClient.Replication.ReplicationManager.IsReplicationGroup(String groupName)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at csharpdatabasefinal.Program.Main(String[] args) in C:\Users\anonym\source\repos\csharpdatabasefinal\csharpdatabasefinal\Program.cs:line 19
Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Enable "native code debugging" in Project -> Properties -> Debug
If that does't work, try adding the MySQL dll via nuget:
Install-Package MySql.Data -Version 8.0.20
User contributions licensed under CC BY-SA 3.0