I'm trying to follow the node-tds example on how to connect and retrieve data from Sql server with node.js http://cretz.github.com/node-tds/
我正在尝试遵循node-tds示例,说明如何使用node连接和检索Sql server中的数据。js http://cretz.github.com/node-tds/
I got no error on connect, but when I try to retrieve data I get the following:
我在connect上没有出错,但是当我试图检索数据时,我得到了以下信息:
"Error: Client must be in LOGGED IN state before executing sql
at TdsClient.sqlBatch (C:\Program Files (x86)\nodejs\node_modules\tds\lib\tds-client.js:101:13)
at Statement.<anonymous> (C:\Program Files (x86)\nodejs\node_modules\tds\lib\tds.js:256:37)
at Statement.execute (C:\Program Files (x86)\nodejs\node_modules\tds\lib\tds.js:2:59)
at Object.<anonymous> (C:\Program Files (x86)\nodejs\edas\app.js:67:6)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Array.0 (module.js:484:10)
at EventEmitter._tickCallback (node.js:190:38)"
I'm logged in, so… I can't figure out what is happening.
我登录了,所以我不知道发生了什么。
1 个解决方案
#1
4
You should execute your statement when the connection has already established, i.e.
当连接已经建立时,您应该执行您的语句,例如。
var tds = require("tds");
var conn = new tds.Connection({
host: "localhost",
port: 1433,
userName: "user",
password: "secret",
database: "MyDb"
});
conn.connect(function(error) {
if (error != null) {
console.error("Received error", error);
} else {
console.log("Now connected, can start using");
}
});
conn.on("connect", function() {
var statement = conn.createStatement("SELECT ProductID, ProductName FROM Products");
statement.on("row", function(row) {
console.log("Received row: ", row.getValue(0));
});
statement.execute();
});
#1
4
You should execute your statement when the connection has already established, i.e.
当连接已经建立时,您应该执行您的语句,例如。
var tds = require("tds");
var conn = new tds.Connection({
host: "localhost",
port: 1433,
userName: "user",
password: "secret",
database: "MyDb"
});
conn.connect(function(error) {
if (error != null) {
console.error("Received error", error);
} else {
console.log("Now connected, can start using");
}
});
conn.on("connect", function() {
var statement = conn.createStatement("SELECT ProductID, ProductName FROM Products");
statement.on("row", function(row) {
console.log("Received row: ", row.getValue(0));
});
statement.execute();
});