- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试在 node.js 中编写脚本来查询 MSSQL 数据库。我是 javascript 的新手,node.js 的新手,VSCode 的新手,但我知道一些关于 SQL 的事情。我有工作代码,但连接似乎永远不会关闭,而且我无法从函数中获取值。
所以,我有这段代码,是从 npm 的例子中得到的:
const sql = require('mssql');
var dbConfig = {
server:'theServer',
database:'theDB',
user:'un',
password:'pw',
port:1433
};
sql.connect(dbConfig).then(pool => {
// Query
return pool.request()
.query('select top 10 * from THE_TABLE')
}).then(result => {
console.log(result);
}).catch(err => {
// ... error checks
})
这有效,我可以看到控制台中记录了 10 个结果。但是,代码永远不会停止运行。如何关闭和停止连接?
我很想把结果保存到一个变量中,所以我把代码改成这样:
const sql = require('mssql');
var dbConfig = {
server:'theServer',
database:'theDB',
user:'un',
password:'pw',
port:1433
};
let theList;
sql.connect(dbConfig).then(pool => {
// Query
return pool.request()
.query('select top 10 * from THE_TABLE')
}).then(result => {
theList= result;
}).catch(err => {
// ... error checks
})
console.log(theList);
这会将“undefined”返回到 theList 的控制台,并且连接似乎永远不会结束,并且脚本永远不会关闭。
我如何获取查询结果并继续前进??
最佳答案
这对我有用。有一个 .close()
方法。
const DB = require("mssql")
const config = require("./config.json")
DB.connect(config)
.then((conn) =>
conn.query("SELECT * FROM table1")
.then((v) => console.log(v))
.then(() => conn.close())
)
关于javascript - 在 node.js 中使用 mssql 关闭 MSSQL 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45681727/
我在我的 Linux(Ubuntu 16.04)服务器上安装 MSSQL 时遇到问题。 我使用了微软的手册,但我总是在同一阶段失败。 实际上,由于内核问题,Docker 不是替代品。 后: sudo
我正在尝试导入 mssql 我有一个 js 文件,它自己可以正常工作,但我需要这样做,以便我可以从 react js 环境中调用该函数,而不仅仅是节点 import React, { Componen
我对 python 比较陌生,对 django 也很陌生。 我正在尝试使用 django 连接到 MSSQL 服务器。我安装了django-mssql(也许它需要放在项目目录中的某个地方?)。 但是,
我想为我的项目使用 mssql 数据库。我采用了 node-mssql 模块 ( https://www.npmjs.com/package/mssql ) 并使用 Microsoft SQL Ser
我试图恢复 centos 服务器内的 mssql 文件。 .bak 文件已放入服务器并将用户设为 mssql。 [![在此处输入图像描述][1]][1] 这是我运行此命令进行恢复时的错误。 sqlcm
我正在尝试建立从 MSSQL (express 2008) 到 Mysql 的特定查询记录集的单向同步。这是该查询。 SELECT [datafk] ,[datahistorypk] ,[da
我正在尝试在 node.js 中编写脚本来查询 MSSQL 数据库。我是 javascript 的新手,node.js 的新手,VSCode 的新手,但我知道一些关于 SQL 的事情。我有工作代码,但
我正在尝试将我的 Golang 应用程序连接到 MSSQL 2014。 我已经成功使用 - https://github.com/denisenkom/go-mssqldb为此,我只在我的 MSSQL
在一个应用程序中,我有一个全局作用域 var db *sql.DB 稍后调用 slcstrSource, slcint64Timestamp, slcstrContent, err := DB_fun
我从服务器 A 创建了一个具有以下规范的 .bak 文件(备份):Windows Server 2003、MSSQL 2005。现在我想在具有以下规范的新服务器 B 上恢复此备份:Windows 8、
我的任务是将 Microsoft SQL Server 2005 数据库迁移到 MySQL 5.6(这些都是本地运行的数据库服务器),非常感谢您的帮助。 -MSSQL 源数据库有 latin1 排序规
我在这里不知所措。总的来说,我对 python 和 odbc 很陌生。但是,我需要找到一种方法,在 Web GUI 的后端有一个 python 脚本,作为我公司的内部工具,从以下位置与 MSSQL 服
下列语句部分是Mssql语句,不可以在access中使用。 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SEL
1.--区分大小写 select * from a where a='AbCdE' collate Ch
-->分段更新 -->Author:wufeng4552 -->Date :2009-10-07 08:13:41 --如:更新'a,a,a,a,a' 第三段a 為 'test'
这几天突然有个想法:希望能够自动监控、收集数据库服务器的磁盘容量信息,当达到一个阀值后,自动发送告警邮件给DBA,将数据库磁盘详细信息告知DBA,提醒DBA做好存储规划计划,初步的想法是通过作业调用
看到网上好多人问为什么我的SQL 2008只能用服务器计算器名登录,而不能用IP登录呢?我也遇到过这个问题,看到网上的回答各有千秋,但没有一个写得比较便于操作的。经过一番网络关键字(SQL 2008
最近在做一个几百万条数据的分页查询,研究了各种方案,在本机上用项目的实际数据库做测试,测试过程 is very 痛苦,不堪回首ing。现在废话不多说,直接上结果,相信这也是大多数搜索答案的人最愿意看
MS SQL基本语法及实例操作 一:建表并初始化 ============================ create database mf2011 --创
地图数据存放在sqlserver 2008中,使用mapxtreme7 开发时,使用Feature.Update()方法时出错的提示包含“MSSQL 将截断字符串或二进制数据” 主要原因就是给某个
我是一名优秀的程序员,十分优秀!