nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.71k stars 29.65k forks source link

nodejs adding multiple records mssql gives connection error #47371

Closed nigelwright7558 closed 1 year ago

nigelwright7558 commented 1 year ago

Version

18

Platform

windows

Subsystem

No response

What steps will reproduce the bug?

Send multiple records to mssql database in a loop. Causes a connection error. An earlier version of nodejs/mssql worked fine

How often does it reproduce? Is there a required condition?

every time

What is the expected behavior? Why is that the expected behavior?

should be able to write records in a loop.

What do you see instead?

connection error if I try to send reords in a loop;

Additional information

async function nigel3() {

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    var price1 = "";
    var price2 = "";
    var price3 = "";
    var price4 = "";
    var price5 = "";
    var image = "";
    var description = "";
    var options1 = "";
    var options2 = "";
    var options3 = "";
    var options4 = "";
    var options5 = "";
    var category = "";
    var stocklevel1 = "";
    var stocklevel2 = "";
    var stocklevel3 = "";
    var stocklevel4 = "";
    var stocklevel5 = "";
    var tax = "";
    var itemswidth = 7 + 4;

    var items = ["Resistors", "1k carbon film resistor.", "0.09", "0.09", "0.09", "0.09", "0.09", "10", "resistor1.png", "10", "10",

        "Resistors", "2k metal film resistor ", "0.09", "0.09", "0.09", "0.09", "0.09", "10", "resistor1.png", "10", "10",
        "Resistors", "3k 1watt resistor ", "0.09", "0.09", "0.09", "0.09", "0.09", "10", "noimageman.jpg", "10", "10",
        "Resistors", "4k 1watt resistor ", "0.09", "0.09", "0.09", "0.09", "0.09", "10", "resistor1.png", "10", "10",
        "Resistors", "5k 1watt resistor ", "0.09", "0.09", "0.09", "0.09", "0.09", "10", "noimageman.jpg", "10", "10",

        "Resistors", "3k 1watt resistor ", "0.09", "0.09", "0.09", "0.09", "0.09", "10", "noimageman.jpg", "10", "10",
        "Resistors", "4k 1watt resistor ", "0.09", "0.09", "0.09", "0.09", "0.09", "10", "resistor1.png", "10", "10",
        "Resistors", "5k 1watt resistor ", "0.09", "0.09", "0.09", "0.09", "0.09", "10", "noimageman.jpg", "10", "10",

        "USB_oscilloscope",
        "PC usb digital storage oscilloscope X. Up to 1,000,000 samples per second. Good for about 20KHz sine wave." +
        "Time bases are  250uS 1mS 5mS 10mS 50mS" +
        "Voltage range is 250mV, 500mV, 1 , 5, 10, 20, 40 and 80 volts per division." +
        "Positive trigger, negative trigger or no trigger." +
        "Trigger level can be set using cursors keys." +
        "Single shot display or roll multiple times display." +
        "Measuring markers to measure voltage and time between two points." +
        "Has an AC/DC switch. Comes with software on a CDROM." +
        "Save/load traces. Print to printer function. Save trace to bitmap file." +
        "It needs a x1 scope probe and printer A-B USB lead which are not included." +
        "Powered by USB bus. Simple FFT display for displaying frequency content."
        , "19.99", "0.09", "0.09", "0.09", "0.09", "10", "usb.jpg", "10", "",

        "PCB_software",
        "2018 Windows version of PCBCAD51 PCB DESIGN SOFTWARE with 127 LAYER AUTOROUTER. " +
        "Runs on Windows XP (SP3) , Windows Vista  and Windows 7, Windows 8 and Windows 10. " +
        "This is a mature product with no bug list, if I find a bug it is fixed immediately. " +
        "Support for this product is second to none, you are supported by the guy who wrote this software. " +
        "Fully supported product sent by first class recorded post. " +
        "Schematic and PCB symbol designer wizards. " +
        "Auto creates SIL, DIL, circular and QUAD PCB footprints from your parameters. " +
        "Schematic entry with auto convert schematic to PCB ratsnest, unconnected pin scanner and single ended net scanner. " +
        "PCB entry with 127 layer rip up and retry auto-router with clearance and continuity check. " +
        "Prints net names on tracks during editing. " +
        "360 degree rotations of pcb components with obround pads. " +
        "Integrity checker, compares schematic and PCB for differences. " +
        "Component locater. Parts list output. " +
        "Schematic/PCB component auto-renumbering and re-annotation. " +
        "RS274X Gerber file generator and NC/Excellon drill file generator. " +
        "Pick and place file generator with fiducial option. " +
        "3D PCB viewer module. " +
        "Output schematic to printer auto-sized.",
        "20.00", "10", "0.09", "0.09", "0.09", "0.09", "cdrom.jpg", "10", "",
        ////////////////////////////////////////////   
        "lastentry", "Resistors", "20.00", "0.09", "0.09", "0.09", "0.09", "10", "usb.jpg", "10", ""];

    var idptr = 1;
    var ptr = 0;

    while ((category = items[ptr * itemswidth]) != "lastentry") {

        description = items[ptr * itemswidth + 1];
        price1 = items[ptr * itemswidth + 2];
        price2 = items[ptr * itemswidth + 3];
        price3 = items[ptr * itemswidth + 4];
        price4 = items[ptr * itemswidth + 5];
        price5 = items[ptr * itemswidth + 6];
        stocklevel1 = 10;
        stocklevel2 = 1;
        stocklevel3 = 1;
        stocklevel4 = 1;
        stocklevel5 = 1;
        image = items[ptr * itemswidth + 4 + 4];
        tax = items[ptr * itemswidth + 5 + 4];
        options1 = "1k";
        options2 = "2k";
        options3 = "3k";
        options4 = "4k";
        options5 = "5K";

        await sql.query(
            "INSERT INTO mvcnode_itemsforsale(Id,category,price1,price2,price3,price4,price5,description," +
            "stocklevel1,stocklevel2,stocklevel3,stocklevel4,stocklevel5,tax,options1," +
            "options2,options3,options4,options5,image)" +
            " VALUES ('" +

            idptr + "','" +
            category + "','" +
            price1 + "','" +
            price2 + "','" +
            price3 + "','" +
            price4 + "','" +
            price5 + "','" +
            description + "','" +
            stocklevel1 + "','" +
            stocklevel2 + "','" +
            stocklevel3 + "','" +
            stocklevel4 + "','" +
            stocklevel5 + "','" +
            tax + "','" +
            options1 + "','" +
            options2 + "','" +
            options3 + "','" +
            options4 + "','" +
            options5 + "','" +
            image + "')"

            , function (err, result) {
                if (err)
                    console.log("resetitem  insert error " + err + '    ' + category);
                else
                    console.log("resetitem ok");

            }

        )

        ptr++;
        idptr++;

    }

}

bnoordhuis commented 1 year ago

Wrong repo. Issue with a third-party module or a bug in your code, not node itself.