An issue occurred while attempting to retrieve information from the database table

'// Encounter: Unable to retrieve data from the table.

// My Code

const sql = require('mssql/msnodesqlv8');
const poolPromise = new sql.ConnectionPool({
    driver: 'msnodesqlv8',
    server: "test.database.windows.net",
    user: "username",
    password: "password",
    database: 'database',
    port: 1433,
})
.connect()
  .then((pool: any) => {
    console.log('Connected to MSSQL')
    return pool
  })
  .catch((err: any) => console.log('Database Connection Failed! Bad Config: ', err))
;

describe('dummy test', () => {

    it('validation', async () => {

        try
        {
            const pool = await poolPromise;

            const result = await pool.request()
            .query('select * from table where username = "Protractor"');

            console.log(result);
        }
        catch(err)
        {
            console.log(err);
        }
    });     
});

Error Identified:

[13:20:25] I/launcher - Executing 1 instance of WebDriver [13:20:25] I/hosted - Using the selenium server at http://localhost:4444/wd/hub Started Connected to MSSQL { RequestError: Invalid column name 'Protractor'. at handleError (C:\Users\automation\node_modules\mssql\lib\msnodesqlv8\request.js:258:21)
at StreamEvents.emit (events.js:189:13) at errors.forEach.err (C:\Users\automation\node_modules\msnodesqlv8\lib\reader.js:37:20)
at Array.forEach () at routeStatementError (C:\Users\automation\node_modules\msnodesqlv8\lib\reader.js:30:14)
at invokeObject.end (C:\Users\automation\node_modules\msnodesqlv8\lib\reader.js:209:11)
at freeStatement (C:\Users\automation\node_modules\msnodesqlv8\lib\driver.js:183:13) at cppDriver.freeStatement (C:\Users\automation\node_modules\msnodesqlv8\lib\driver.js:163:13) originalError: { Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'Protractor'. sqlstate: '42S22', code: 207 }, name: 'RequestError', number: 207, state: '42S22' }

Answer №1

Using double and single quotes in T-SQL serves different purposes.

Consider the following alternatives:

let data = await db.query("SELECT * FROM users WHERE name = 'John Doe'");

or you can try this approach:

let data = await db.query('SELECT * FROM users WHERE name = "John Doe"');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to simulate the parameters of a method callback from an external dependency in Nodejs

Imagine a scenario where I have the following structure: lib/modules/module1.js var m2 = require('module2'); module.exports = function(){ return { // ... get: function(cb){ m2.someMethod(params, function(error, ...

What steps do I need to take to develop a syntax similar to Vue.js using only plain JavaScript?

<div id=""> <span>{{msg}}</span> </div> Assume that {{msg}} is a variable in JavaScript. Now, I aim to locate the parent tag of {{msg}} and replace its content with a new value using innerHTML, where {{msg}} serves as an identi ...

`Where to include controller.js scripts in an Angular application`

As I dive into learning angular.js with .NET MVC, one major issue that keeps coming up is the fact that many tutorials advise referencing multiple controllers and services in the main (_Layout) page, which can make it quite messy. Although it may seem sim ...

Struggle with typescript integration with emotion and styled components

Issue Description: I encountered an issue while working with typescript and emotion/styled libraries. When attempting to specify the type of the parent component that wraps a styled component, I faced difficulties. The scenario involves a parent componen ...

Error encountered in app.module.ts file of Angular 2 application

My friends and I are working on a big school project, creating a cool web app. Suddenly, I encountered some errors in my app.module.ts file that I haven't seen before. It's strange because they are showing up out of nowhere! The error: Error:( ...

Issue with NullInjectorError: Failure to provide a custom component - Attempting to add to providers without success

I keep encountering errors during my test attempts... Despite looking into similar issues, I am still facing problems even after adding my custom LoginComponent to app.module.ts providers. It is already included in the imports section. app.module.ts @Ng ...

Adjust the positioning of a class element

I have an eye icon that changes position when clicked. Initially, it is set to left: 10%;, but if there is a DOM element with the ID login-section, it should be repositioned to left: 50%;. I attempted to use document.getElementsByClassName('fa-eye-sl ...

How can we insert data at the bottom of a table to begin with?

I am looking to add information retrieved from the iTunes API to the end of a table. The first album I receive will be placed at the very end, with each subsequent album adding on while pushing the previous one up in the hierarchy. Any ideas on how I can ...

How does the Week-To-Date performance this year stack up against the same period last

Currently, I am seeking to analyze the sales growth data from the current week to the same week last year. This comparison needs to be dynamic for daily reporting purposes, ending on the previous day of the week-to-date (WTD) sales, through SSRS for email ...

Locating every quadrilateral within a mesh

I'm currently using Three.js to load a mesh and I am attempting to texture each quad individually. At the moment, I am able to texture each face (triangle), but I am unsure of how to determine if the current triangle and the last triangle are part of ...

Updating the state of an object within a mapping function

I've been struggling with this issue for two days now. Despite my efforts to find a solution online, I am still stuck and starting to believe that I might be missing something. The main functionality of the app is to click a button and watch an apple ...

Error: Unable to retrieve the value of 'secret' as it is undefined when attempting to assign a response cookie in Express framework

Today's operation that I've carried out countless times seems to be going awry. For some reason, I am unable to set a refresh token cookie using Express. Here is the error message in full /home/me/Code/apGymBE/node_modules/express/lib/response.j ...

Transferring User ID from Google Tag Manager to GA4 Problem

I'm currently working on a new project and adding some dummy data to the dataLayer of Google Tag Manager from the \_app.tsx file. <Script id="gtg" strategy="beforeInteractive"> { window.dataLayer = window.dataLayer || &b ...

Why are JavaScript errors constantly popping up when I use Django Pipeline?

After configuring Django Pipeline (version 1.3.15) for a specific group of JS files, I ensured they were in the correct order based on their appearance on my page. The collectstatic process went smoothly and when viewing the source, it looked like all th ...

Having trouble loading select fields using AJAX within Wordpress? Update and find a solution!

UPDATE: I am struggling to iterate through the response object and populate a select field using my ajax function. Although I have tried using a for loop instead of each(), the select field gets populated with "undefined". Any suggestions on how to resolve ...

SQLPLUS encountered a right parenthesis error for the data type 'INT(8)'

I'm experiencing an issue while trying to address this particular error SQL> CREATE TABLE Reservation_21BAI1750( 2 PNR number(9), 3 Journey_Date Date NULL, 4 No_of_Seats INT(8) ZEROFILL CHECK (No_of_Seats < 50), 5 Address varchar ...

Trouble with uploading images to folder using PHP and AJAX is causing confusion

I'm having trouble uploading a photo using ajax and php. Despite following advice from other sources, I can't seem to make it work. Is there anything in my code that appears to be incorrect? The ajax request seems to go through successfully, so ...

Working with intricately structured objects using TypeScript

Trying to utilize VS Code for assistance when typing an object with predefined types. An example of a dish object could be: { "id": "dish01", "title": "SALMON CRUNCH", "price": 120, ...

Using React-Router-Native to send an image as a parameter

I am encountering an issue while attempting to pass an image as a parameter in react-router-native and retrieve the data from location.state. Typically, I use the following code to display an image: import Icon from '../image/icon.png'; <Vie ...

The value of form.formGroup is not equivalent to the output of console.log(form)

Having an issue here. When I send a Form to a component, If I use console.log(form), it displays the object correctly. However, when I check the form in the console, the form.formGroup.value looks fine (e.g. {MOBILE0: 'xxx', PHONE0: 'xxx&ap ...