javascript - Nodejs mssql批量插入RequestError:无效的对象名称'table_name'
问题描述
我正在尝试使用 nodejs mssql 包批量插入现有表。即使我的表已经存在,它也会给出错误,因为无效对象名称“my_test”并且我已经尝试了“db.schema.tablename”或“schema.tablename”两者。请帮助我,并提前致谢。我的代码部分如下 - :
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;
}); ```
解决方案
推荐阅读
- python - 我想在星球动画中留下足迹
- angular9 - 将 Angular 8 升级到 9 后出现 Linting 错误
- python - 未创建会话:此版本的 ChromeDriver 仅支持 Chrome 版本 88
- javascript - appme 主题中的菜单与 wordpress 中的哈希 id 不同步
- sql - 查找表中的所有序列
- reactjs - React Route 与其他页面重叠
- excel - Excel:使用公式处理数据
- c - ioctl KVM_RUN 在什么情况下返回?
- ms-access - 访问:记录锁定 - 编辑的记录属性无法正常工作
- sql - 有条件地选择多行并将其插入 SQL Server 中的单行