mustafakemalgilor / arduino-mssql

THIS PROJECT IS NOW DEPRECATED; PLEASE USE TDSLITE INSTEAD! https://github.com/mustafakemalgilor/tdslite A TDS 7.0 implementation for Arduino, allowing connection to Microsoft SQL Server and running queries. (using UIPEthernet or Ethernet)
MIT License
21 stars 11 forks source link

Inserting data into the database stops #9

Closed 5arid closed 1 year ago

5arid commented 2 years ago

Hi The following code must insert values from 1 ~ 1000. But every time it stops when it reaches 168! I feel that it runs out of ram memory?! How to fix it? I am using arduino mega 2560 and sql server 2014 Thanks in advance

`#include "sqlard.h"

EthernetClient client; static byte server_IP[] = {1, 1, 1, 1}; SQLard MSSQL(server_IP, 1433, &client);

void setup() { Serial.begin(9600); while (!Serial); Serial.println("serial started"); delay(1000);

static byte Mac[] = {0x74, 0x69, 0x69, 0x2D, 0x30, 0x31}; static byte IP[] = {192, 168, 1, 101}; static byte Dns[] = {192, 168, 1, 1}; static byte Gateway[] = {192, 168, 1, 1}; static byte Subnet[] = {255, 255, 255, 0}; Ethernet.begin(Mac, IP, Dns, Gateway, Subnet); Serial.println("ethernet connected"); delay(1000);

MSSQL.connect(); Serial.println("connected to sql server ip"); delay(1000);

MSSQL.setCredentials(L"arduino", L"ard_login", L"ard_password", L"hostx"); Serial.println("set user & pass"); delay(1000);

MSSQL.login(); Serial.println("login ok"); delay(1000); }

void loop() { for (int n = 1 ; n < 1000 ; n++) { char sql_char[100]; sprintf(sql_char, "INSERT INTO [dbo].[myTable] ([data]) VALUES (%d)", n); wchar_t sql_wchar[100]; for (int i = 0 ; i < 100 ; i++) sql_wchar[i] = sql_char[i];

MSSQL.executeNonQuery(sql_wchar);
Serial.print("Inserted : ");
Serial.println(n);
delay(1000);

} }`

mustafakemalgilor commented 2 years ago

Hi @5arid,

I reviewed the code path and didn't see any reason for memory to fill up. All allocations made on the execution path are either stack or auto-free heap allocations. OTOH, flooding the server like this may have caused the response packets to fragment, and the code perhaps could not handle the response message tokens properly. That may cause https://github.com/mustafakemalgilor/arduino-mssql/blob/master/sqlard.h#L1374 loop to go forever (it is an unhandled condition).

I am currently rewriting this library from scratch in a production-worthy manner. If you are going to do anything serious with this library, I'd suggest waiting for the first release of "tdslite" (a.k.a. the successor of SQLard). I am planning to release it a few months from now.

5arid commented 2 years ago

Thanks for the replay I am not using this library for serious project but I want to fix it if possible. Is there anyway to check arduino memory while running? Also it would be nice if we can use this library on ESP-01!

mustafakemalgilor commented 2 years ago

Yes, you should be able to check it. See static int freeRam(const char * who) function in sqlard.h, that will give you an idea to how to do so.

With regard to running on other boards, the new library (tdslite) will be board-agnostic, so you should wait for it. Fingers crossed 🤞