Looking for MYSQL connection usings [FEZ Hydra]

Hello,

I would like to use a MYSQL (phpMyAdmin) connection with a .NET Gadgeeter (4.2) project.
I already ran a project (Windows apply) and it work. I think some usings are missing but i don’t know what they are.
I installed “mysql-connector-net-6.6.5”

Thanks for answers :wink:

And what do you want to do with the gadgeteer app?

The Spider mainboard supports SQLite http://wiki.tinyclr.com/index.php?title=SQLite
This may get you going

Does it work on Fez Hydra ? Sorry i didn’t write it ! Just edited topic !
@ David, i need to send datas to my database.

No its not part of the OSHW line up. SQLite is part of the premium hardware lineup of swhich the spider is one.
I guess there is no reason why you couldnt write your own SQL Library for the OSHW boards? release it to the community and get loads of Kudos

If I understand you correctly you want to access a MySQL Database on some server from your NETMF device.
To do so you would need a MySQL driver for NETMF.
I think “mysql-connector-net-6.6.5” is the .NET driver for windows.
If you can find a similar thing for NETMF, then it’s easy (doubt that it exists)
If not, you would have to write one, which will not be so easy I think.

If you can use some kind of windows based gateway, then I would go this way:
Create a Windows app/service using “mysql-connector-net-6.6.5” to access the DB
Open an TCP/IP Port (Server) in your gateway app/service.
In NETMF Device connect to this TCP/IP Server.
Comunicate with any protocol you like betwenn NETMF Device and gateway app/Service and route it through to MySQL DB.

Have a look here for info http://www.sqlite.org/
and licensing info here SQLite Copyright it looks like its public domain

Adding it for Hydra using RLP Light is another option. Although it is not a simple task.

@ MugiwaraOz - You wont be able to talk “directly” to the MYSQL database because there are no drivers for this on netmf.
How will the gadgeteer app communicate with you dektop app? How these 2 will be connected?

I want to pick up my datas into a circular buffer, then send it to my database using ENC28 module (ethernet module). My database is located in a computer on my network.
I’m a begginer in NETmf, so i don’t understand everything ! But thank you to all trying to help me :wink:

In that case I would make a lightweight web service that inserts the data into the DB and will call that service from NetMF device.

You can not use any precompiled assembly which was made for the Windows .net Framework, and copy it to your NETMF Device.
You need specially compiled assemblies which targets the .net Microiframwork (which is a subset of the big .net in some parts, but also a bit different in others).

To comunicate over the ENC28 you can use raw TCP or UDP sockets, or you use any ‘higher level’ servers/clients which already exists, like FTP, http, …

I assume that the MySQL server is a TCP server that requires a ‘special’ protocoll which should be described on the MySQL web page.

What you need to do now is to implement this protocol using raw TCP sockets and build an API around it.
This API should be similar to an already existing API which exists for MySQL (Like the mysql-connector-net you mentioned)

Have fun :wink:

I seccond this one, would be the fastest solution.

I also would like to add. Please check COSM. And this an example how it is used from NetMF:

http://www.tinyclr.com/forum/topic?id=7795

actually i’m setting up an http server. Is it possible to do it with this ?

Yes. You can set up a simple page that will write to DB and use GET or POST request to that page to serve the data from the device.

1 Like

I am doing the exact same thing. I am calling a web page (php) and inserting data to MySQL.


HttpRequest result = new HttpRequest();

            _request = (HttpWebRequest)HttpWebRequest.Create(url);
            _request.Method = "POST";
            _request.ContentType = ContentType;
            _request.Timeout = 30 * 1000;
            _buffer = data;

if (_buffer != null)
                {
                    _request.ContentLength = _buffer.Length;
                    Stream s = _request.GetRequestStream();
                    s.Write(_buffer, 0, (int)_buffer.Length);
                    s.Close();
                }
                response = _request.GetResponse();
                Stream sr = response.GetResponseStream();
                StreamReader readStream = new StreamReader(sr);
                string str = readStream.ReadToEnd();
                RaiseSucceed((HttpWebResponse)response, str);

Calling the function (up function)


JsonObject o = new JsonObject();
                JsonObject data = new JsonObject();
                o.Add("Measuring", "Temperatures");
                o.Add("Data", data);
                data.Add("Location", "LivingRoom-Computer");
                data.Add("Data", _PostDataTemperature);
                _PostedData.Add(o);

                o = new JsonObject();
                data = new JsonObject();
                o.Add("Measuring", "Humidities");
                o.Add("Data", data);
                data.Add("Location", "LivingRoom-Computer");
                data.Add("Data", _PostDataHumidity);
                _PostedData.Add(o);
                
                _PostDataTemperature = new JsonArray();
                _PostDataHumidity = new JsonArray();
                r = HttpRequest.CreatePostRequest(@ "http://" + Program._SERVERROOT + "/Process/Microcontroler/PostMeasurements.php", _PostedData.ToString().ToBytes(), "application/json");

It is not complete code, but you will get the idea.

<?php
	require_once '../../Classes/Table.php';

	try
	{
		$data = json_decode($GLOBALS[ 'HTTP_RAW_POST_DATA' ]);
		foreach ($data as $item)
		{
			$measuring = $item->Measuring;
			$data = $item->Data;
			$table = new Table($measuring);
			$Location = $data->Location;
			$DatesValues = $data->Data;
			$InsertData = Array();
			foreach ($DatesValues as $DateValue)
				array_push($InsertData, array($Location, $DateValue->Date, $DateValue->Value));
			$table->InsertAll(array("Place", "DateTime", "Value"), $InsertData);
		}
		echo "OK";
	}
	catch (Exception $e)
	{
		echo $e->getMessage();
	}
?>
1 Like

I don’t undertand everthing in you code. I can’t see your attributes types and method like RaiseSucceed or Json …
Could you send me your project files at: m.chauzal@ gmail.com
Or codeshare project in the forum.

Thank you ! =)

This would be a hard thing to do. The project is to big.
You can discard RaiseSucceed. I override HttpRequest.
Json: http://www.tinyclr.com/codeshare/entry/282

If you have any problems or don’t understand something, just write.