Nodejs mssql bulk insert RequestError: Invalid object name 'table_name'

Viewed 395

I am trying to use nodejs mssql package for bulk insert into existing table.It give error as Invalid Object Name 'my_test' even my table is already there and i have tried 'db.schema.tablename' or 'schema.tablename' both. Please help me on that and Thanks in advance. My code part is like below - :

async function getPool(name) {
  if (!Object.prototype.hasOwnProperty.call(pools, name)) {
    const pool = process.env.NODE_ENV.trim() === 'local' ? new sql.ConnectionPool(configLocal) : new sql.ConnectionPool(config);
    const close = pool.close.bind(pool);
    pool.close = (...args) => {
      delete pools[name]
      return close(...args)
    }
    await pool.connect();
    pools[name] = pool;
  }
  return pools[name];
}

const pool = await getPool('default');
        const table = new sql.Table('my_test'); // or temporary table, e.g. #temptable
        table.create = false;
        table.columns.add('id', sql.Int, { nullable: false,primary:true,identity:true});
        table.columns.add('name', sql.VarChar(50), { nullable: false });
        table.rows.add(10, 'test');
        table.rows.add(11, 'test 2');
        const request = new sql.Request(pool);
        request.bulk(table, (err, result) => {
            console.log("Result  ", result, err);//return result;
        }); ```
 
0 Answers
Related