C# Keyword not supportet - CertificateFile - MySqlConnection - c#

I am trying to establish a SSL connection to a MySQL Server.
Now I get the following error, when trying to connect:
Unhandled Exception:
System.ArgumentException: Keyword not supported.
Parameter name: CertificateFile
here is my Connection String:
MySqlConnection connection = new MySqlConnection(
"database=database;user=sslclient;" +
"CertificateFile=C:\\Users\\LSP\\documents\\visual studio 2017\\Projects\\App1\\App1\\client.pfx;" +
"CertificatePassword=XXX;" +
"SSL Mode=Required");
Do you know what the fault is ? As mentioned in
https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-ssl.html
it is valid.
I also tried to manage this with a MySqlConnectionStringBuilder, but this also dont work:
enter image description here
I am using the newest Version of MySql.Data from the NuGet Manager.
Thank you for you help,
Louis

Related

How to connect to Db2 from .NET 7

I'll need to connect to a Db2 server with C#.
On Nuget I've found IBM.Data.DB2.Core V3.1.0.600.
This package seems to be what I'm looking for but I don't get it work. Whenever I try to open the connection I'm getting an error.
DB2ConnectionStringBuilder sb = new DB2ConnectionStringBuilder
{
UserID = "MK1",
Password = "XXXX",
Server = "rei5",
Database = "testrei5"
};
DB2Connection connection = new DB2Connection(sb.ConnectionString);
connection.Open();
The error message is:
IBM.Data.DB2.Core.DB2Exception (0x80004005): ERROR [08001]
[IBM] SQL30081N A communication error has been detected.
Communication protocol being used: "TCP/IP".
Communication API being used: "SOCKETS".
Location where the error was detected: "172.17.1.50".
Communication function detecting the error: "connect".
Protocol specific error code(s): "10061", "*", "*". SQLSTATE=08001
According to the official docs, I've run these commands in the bin folder from nuget.
db2cli writecfg add -database BLUDB -host hostname -port 50000
db2cli writecfg add -dsn alias -database BLUDB -host hostname -port 50000
I've set alias to testrei5 and hostname to rei5. This worked after I've renamed the db2dsdriver.cfg.sample file in the cfg directory to db2dsdriver.cfg.
However, my connection still doesn't open.
Am I missing something here?

System.Collections.Generic.KeyNotFoundException upon attempting to log in to .NETCore application with MySqlClient

I'm building an contact manager application using .Net 5.0 in Visual Studio 2019 Community Edition. I am using MySql Connector (MySql.Data.dll) to connect to MySql database. The connection works, though only after adding the older version (6.1.2) - it is possible to insert data to the database. However, upon searching through the database (logging in or verifying whether the username already exists - here the error is more specific, listed below) I am receiving such an error:
System.Collections.Generic.KeyNotFoundException: „The given key
'utf8mb4' was not present in the dictionary.”
Here is my connection string:
MySqlConnection con = new MySqlConnection("datasource=localhost; port=3307; username=root; " +
"password=; database=csharp_contact_manager_db; CharSet=utf8;");
Here's my code for logging in functionality:
Database db = new Database();
MySqlDataAdapter adapter = new MySqlDataAdapter();
DataTable table = new DataTable();
MySqlCommand command = new MySqlCommand("SELECT * FROM `user` WHERE `username` = #un AND `password` = #pass", db.getConnection);
command.Parameters.Add("#un", MySqlDbType.VarChar).Value = textBoxUsername.Text;
command.Parameters.Add("#pass", MySqlDbType.VarChar).Value = textBoxPassword.Text;
adapter.SelectCommand = command;
adapter.Fill(table);
The aforementioned error always occurs for adapter.Fill(table) line.
Here's the query I'm using for verifying whether the username already exists in the database:
string query = "SELECT * FROM 'user' WHERE 'username'=#un";
In case of the above verification, this is an error I'm receiving:
MySql.Data.MySqlClient.MySqlException: „You have an error in your SQL
syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near ''user' WHERE
'username'='user'' at line 1”
I downgraded the MySql.Data.dll version, since this is what I've receiving so far when attempting to connect to the database with the version of 8.0.17:
System.TypeInitializationException: „The type initializer for
'MySql.Data.MySqlClient.MySqlConnectAttrs' threw an exception.”
FileNotFoundException: Could not load file or assembly
'System.Management, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file
specified.
I've already seen similar posts regarding this, none of the suggested solutions helped in my case though.
Cheers,
Filip

How to solve mysql database-unity connection problem using mysql connector and c#?

I have created a server with Unity 2019, collecting some data and I struggle to connect to my MySQL database. The database is stored locally.
I can access my DB in a simple C# project (not Unity) but have no luck with Unity.
Do you have any idea on how to solve this issue ?
So far I found some post about importing dll from the MySQL connector.net :
https://sigitov.de/how-to-add-mysql-capabilities-to-a-unity-application/
https://www.codedojo.com/?p=2132
How do I import MySql Connector into Unity Project?
I added the following dll :
From MySQL Connector.Net 8.0 (in MySQL\ConnectorNET8.0\Assemblies\v4.5.2 folder)
MySQL.Data.dll
BouncyCastle.Crypto.dll
Renci.SshNet.dll
SshNet.Security.Cryptography.dll
Google.Protobuf.dll
From Unity Mono2.0 :
I18N.CJK.dll
I18N.dll
I18N.MidEast.dll
I18N.Other.dll
I18N.Rare.dll
I18N.West.dll
Using this I was able to use MySql.Data.MySqlClient and create a MySqlConnection.
However when I try to open the connection I get :
Error: 0 : Unable to connect to any of the specified MySQL hosts.
I verified the string used to create the MySqlConnection by using the same string in another C# project and it works fine there.
I tried adding charset (Unity3D connection to MySQL error), putting capital letters ... but no improvement.
At this point I don't know if Unity is blocking in some way the connection or if I'm missing something.
It seems that I am not the only one struggling with this (Accessing MySQL database using c# on unity?, https://www.reddit.com/r/Unity3D/comments/902wy3/best_way_to_retrieve_game_data_item_list_stats/, https://www.reddit.com/r/Unity3D/comments/c7b101/is_it_possible_to_use_systemdatasqlclient_in/, https://www.reddit.com/r/Unity3D/comments/8c25mu/unity_server_how_to_connect_to_mysql/).
I am aware that some people use PHP (or some other webserver) as a "middleman" between Unity and MySQL but it sounds a bit overkill for something working just fine in C# outside Unity...
Here is the code I use for the connection to MySQL, connection is a MySqlConnection, private member of my class, I tried those lines in the classic Unity Start function of my class
string dataSource = "localhost";
string port = "3306";
if (connection != null)
{
connection.Close();
}
string connStr = "Datasource=" + dataSource +
";port=" + port +
";username=" + Global.Username +
";password=" + Global.Password +
";database=" + dbName;
connection = new MySqlConnection(connStr);
try
{
Debug.Log("Connecting to MySQL...");
connection.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Just to let you know : I also posted the question on reddit (r/Unity3D)

using method 'mysql_native_password' failed

An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'#'localhost' (using password: NO)
I need to connect my database to the report viewer in visual studios however this error always appears and i dont know what changes i have to make...the password was already set to 'root' however this error still appears, I want to know what "(password: NO)" means since this only appeared when i accidentally flushed out the privaleges.
Password NO just means that you don't pass over a password.
Are you connecting like this:
string connsqlstring = "SERVER=" + server + ";PORT=" + port + ";user=" + user + ";password=" + password + ";database=" + databank;
sqlconn = new MySqlConnection(connsqlstring);
sqlconn.Open();
Or how are you doing it ?
Another thing is, i had problems before with Root and made a new User with which i now connect.
Maybe that helps.
Cheers,
Frozen :)

MySQL Connection with C#

I have a code written in JAVA:
String host = "jdbc:mysql://online/find";
String username = "test";
String password = "test";
And its working fine. But I want to use the same database MySQL with C#. And I am doing this:
try
{
string myConnStr = "Server=//online/find; " +
" Port = 3306; "+
" DATABASE=finder; " +
" UID=test;Password=test;";
MySqlConnection MySqlConn = new MySqlConnection(myConnStr);
MySqlDataAdapter MySqlAdapter = new MySqlDataAdapter();
MySqlAdapter.SelectCommand = new MySqlCommand("Select * from finder.Customer", MySqlConn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(MySqlAdapter);
MySqlConn.Open();
DataSet ds = new DataSet();
MessageBox.Show("Connected");
MySqlConn.Close();
}
But I am getting Error: "Unable to connect to any of the specified mysql hosts"
I even tried with
IP address in connection string but still its not working.
I have checked these posts already:
Unable to connect to any of the specified mysql hosts. C# MySQL
unable to connect to any of the specified mysql hosts. c#
According to the documentation should be:
string myConnStr =
"Database=finder;Data Source=//online/find;Port=3306;User Id=test;Password=test";
However for me Connection strings could be hard to remember.
Its very easy to make a mistake when you write it manually.
One advice is to use the server explorer to connect to your database. Then right click on your database icon > select properties ... you will see the connection string copy and paste .
Voilà!
Server Explorer:
Properties:
Did you install the MySQl Connector for Microsoft Application. If yes then add a reference to MySql.dll from your C# application, then use the below connection string
string myConnStr = "server=yourMySqlServerHostorIP; port=MySqlPort;uid=username;pwd=password;initial catalog=dbname";
To download mysql connector go to http://dev.mysql.com/downloads/connector/net/.
Let me know if it works.
My first idea about the issue is "this has nothing to do with param names for username and password". You are not getting an error like:
user "null" cant login
Java and C# work on totally different foundation (Oracle vs. Microsoft) I don't know Java but I think the libraries for connecting to a remote location must be different.
I think the host URL you used is the problem:
Server=//online/find;
I use MySQL with my C# projects and I define the host value as:
localhost or 127.0.0.1
an IP address (xxx.xxx.xxx.xxx)
a host url (my.dbserver.com)
here is a working MySQL connection string:
<add name="dbConnNews"
connectionString="server=xx.xx.xx.xx;database=yyyyy;User
Id=zzzzzz;Password=**********;"
providerName="MySql.Data.MySqlClient" />
Try to connect to the server via IDE Server Explorer --> Data Connections and observe the connection string generated.

Categories

Resources