Busca en nuestro Blog. Encontrarás múltiples aplicaciones, soluciones, ejemplos de código. Navega utilizando la nube de etiquetas o busca utilizando criterios específicos

SQLServer library for Arduino Devices



In this post will be shown some comments about the SQLServer library arduino-mssql.

This library is a connecting MSSQL via  industrial Arduino. It is a basic implementation which you can use to run queries like SELECT, INSERT, UPDATE and DELETE. 

To see how it works we have an example. In this example we connect to the SQL Server with a client, and M-Duino for example, and sends some queries. 


Here you can find the link of the library:

Link arduino-mssql 

You will see that there are two sample files: sqlard-test.ino and sqlard-test.ccp


First of all you have to connect to a server. For that, we can connect to the server using Ethernet. We define a client and this client will connect to the server. Once is connected, we can send senteces to the data base. To make our queries we have the function executeNonQuery(), you can see that in the example.  

Here you have a code example with some comments next in bold type. 

#include <Ethernet.h>
#include "sqlard.h"

uint8_t Ethernet_MacAddr[6] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; /* MAC ADRESİ */
static byte Static_IPAddr[] = { 172,16,1,2 };            
static byte Gateway_IPAddr[] = { 172,16,1,1 };
static byte Subnet_Mask[] = { 255,255,0,0 };
EthernetClient client; // Create a client

SQLard MSSQL(Gateway_IPAddr, 1433, &client); // Create the connection with the Server Data Base
void setup() {
  // put your setup code here, to run once:
  while (!Serial); 
  Ethernet.begin(Ethernet_MacAddr, Static_IPAddr, Gateway_IPAddr, Gateway_IPAddr, Subnet_Mask); // Establish the connection of the client with the server 
  if(MSSQL.connect()) // Check if the connection with the Data Base is correct
      MSSQL.setCredentials(L"arduino", L"ard_login",L"ard_password",L"hostx"); // Login to the Data Base
      MSSQL.login(); // Now we are able to send queries

void loop() {
  // put your main code here, to run repeatedly:
  static int loop_count = 0;

  long affected_rows = MSSQL.executeNonQuery(L"INSERT INTO [dbo].[test]([data]) VALUES('deger1234') "); // Make an INSERT queri.     
// [dbo].[test]([data]) would be the table
long yeni = MSSQL.executeNonQuery(L"DROP TABLE [dbo].[test23]"); // Make a DROP query. [dbo].[test23] would be the table Serial.print(affected_rows); // When you make an executeNonQuery it returns the number of affected rows Serial.println(" row(s) affected."); if (!client) { Serial.println("disconnecting."); client.stop(); } if(++loop_count == 10) { MSSQL.executeNonQuery(L"DELETE FROM [dbo].[test]"); // Make a DELETE query to delete all rows, but not the table. Like a Reset after 10 queries
// [dbo].[test] would be the table loop_count = 0; } }

¿Quieres más información?

Con la tecnología Open Source, puedes ejecutar tus propias instalaciones.

Rellena el formulario y contactaremos contigo lo más pronto posible.

Enviar  Por favor, completa el formulario correctamente.