MariaDB and c#
-
Does anyone have a code snippet that shows how to connect to a MariaDB database? Many of the examples I've found point to a MySql-compatible assembly. Is that the way you have to do it? I have no idea what assemblies to add to my references in a test project. I've not used MySql in donkey's years so I have absolutely no idea how to kick-start things using MariaDB. Once I know what references to add and the syntax of a connection string particular to MariaDB's requirements I'll be okay from there. TIA. Edit: Forgot to mention I d/l the version 10.0 beta. Everything installed okay but I don't have any references visible to either MySql or MariaDB in a dotnet project.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
-
Does anyone have a code snippet that shows how to connect to a MariaDB database? Many of the examples I've found point to a MySql-compatible assembly. Is that the way you have to do it? I have no idea what assemblies to add to my references in a test project. I've not used MySql in donkey's years so I have absolutely no idea how to kick-start things using MariaDB. Once I know what references to add and the syntax of a connection string particular to MariaDB's requirements I'll be okay from there. TIA. Edit: Forgot to mention I d/l the version 10.0 beta. Everything installed okay but I don't have any references visible to either MySql or MariaDB in a dotnet project.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
the MySQLConenctor is normally a seperate installation from MySQL Connector[^] once you download and install that usually you just add a reference to the project like you would do any normal installed .net library.
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
the MySQLConenctor is normally a seperate installation from MySQL Connector[^] once you download and install that usually you just add a reference to the project like you would do any normal installed .net library.
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
Thanks a lot Simon. I downloaded it and ran the install. I added a reference to the assembly in the installation folder and I can see a shed-load of MySql classes. I'll wire one up to my test database and see if it can connect to it. So, I'm a step on the road with a way to go...
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
-
Does anyone have a code snippet that shows how to connect to a MariaDB database? Many of the examples I've found point to a MySql-compatible assembly. Is that the way you have to do it? I have no idea what assemblies to add to my references in a test project. I've not used MySql in donkey's years so I have absolutely no idea how to kick-start things using MariaDB. Once I know what references to add and the syntax of a connection string particular to MariaDB's requirements I'll be okay from there. TIA. Edit: Forgot to mention I d/l the version 10.0 beta. Everything installed okay but I don't have any references visible to either MySql or MariaDB in a dotnet project.
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.
I downloaded and installed the file that Simon provided at this link[^] (select the one called ADO.NET Driver for MySQL (Connector/NET). When you follow the download links the sly folks at Oracle/MySql try to make logging in to their website "mandatory" and it's easy to miss the tiny "No thanks, just start my download" link below it, so there's no need to register. When you've downloaded and installed it create a project and add an assembly reference to "C:\Program Files (x86)\MySQL\MySQL Connector Net 6.7.4\Assemblies\v4.0\MySql.Data.dll" (obviously, select your Program Files location and the framework version as appropriate). If you have MariaDB installed chances are you have the IDE tool, HeidiSQL installed. I used that to create a new session, database and a table. In HeidiSQL, the menu Tools -> User manager is where I created a user registration and pointed it to "home", 127.0.0.1 and I set the access rights to full, the usual suspects. Here's a code fragment I slapped into a console app (apologies if it doesn't format nicely):
string connStr = "server=127.0.0.1;uid=DogzBolx;pwd=password;database=imagecatalog;"; MySqlConnection conn = new MySqlConnection(connStr); conn.Open(); string sql = "select \* from data order by count desc;"; MySqlDataAdapter da = new MySqlDataAdapter(sql, conn); DataTable data = new DataTable(); da.Fill(data); foreach(DataRow row in data.Rows) { string md5 = Convert.ToString(row\[0\]); int count = Convert.ToInt32(row\[1\]); Console.WriteLine(md5 + " " + count); } conn.Close();
Excuse my glib database name. :) I ran the app and (bless my cotton socks) it worked! Anyway, it works fine, and it's rather jolly quick. Whether MariaDB can do what I'm familiar with using SQL Server I can't say but it seems to offer a lot of things. HeidiSQL itself is rather nice. I don't know if there are other tools to maintain MariaDB databases but seeing it's all part of the MariaDB-related family it's certainly works just fine. That's my $0.02c worth. :-D
If there is one thing more dangerous than getting between a bear and her cubs it's getting between my wife and her chocolate.