简体   繁体   中英

I can connect to the database via SQL Server 2008, but can't connect via Node.js

So, without any special stuff, I can connect to a remote SQL server via SQL Server 2008 (Server type: Database Engine, Authentication: SQL Server Authentication).

I take the same Server name and go into Node.js on my computer and use https://github.com/felixge/node-mysql as my mysql connector, and I get the following:

var mysql = require("mysql");

var connection = mysql.createConnection({
host:   "(server name)",
user:   "myusername",
password:   "mypassword",
database:   "mydb"
});

connection.connect();

Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
--------------------
at Handshake.Sequence (C:\node_modules\mysql\lib\protocol\sequences\Sequence
.js:15:20)
at new Handshake (C:\node_modules\mysql\lib\protocol\sequences\Handshake.js:
9:12)
at Protocol.handshake (C:\node_modules\mysql\lib\protocol\Protocol.js:42:50)

at Connection.connect (C:\node_modules\mysql\lib\Connection.js:73:18)
at Object.<anonymous> (C:\server.js:12:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

Strangely enough, I try using the mysql command line, and I can't connect through that either:

C:\>mysql -h (IP)
ERROR 2003 (HY000): Can't connect to MySQL server on '(IP)' (10061)

I'm at a loss! I'm using Windows 7, and everything I can come up

Sadly, SQL Server and MySQL doesn't share anything but the SQL and some syntax. The protocol of the connection aren't the same. So the node-mysql package won't work for you.

You can find the SQL Server driver on this MSND page with the explication on how to use it or directly on the GitHub page of the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM