Sequelize:无法连接到SQL Server - 正在传递错误的端口

时间:2017-08-11 21:10:16

标签: sql-server node.js sequelize.js

我正在尝试连接到SQL Server实例,但在尝试连接时正在定义错误的端口。

  

无法连接到数据库:{SequelizeConnectionRefusedError:connect ECONNREFUSED 127.0.0.1:3306
  在Handshake._callback(C:\ test \ ExpressGeneric \ node_modules \ sequelize \ lib \ dialects \ mysql \ connection-manager.js:80:20)
  在Handshake.Sequence.end(C:\ test \ ExpressGeneric \ node_modules \ mysql \ lib \ protocol \ sequences \ Sequence.js:88:24)
  在Protocol.handleNetworkError(C:\ test \ ExpressGeneric \ node_modules \ mysql \ lib \ protocol \ Protocol.js:363:14)
  在Connection._handleNetworkError(C:\ test \ ExpressGeneric \ node_modules \ mysql \ lib \ Connection.js:428:18)           在emitOne(events.js:96:13)           在Socket.emit(events.js:188:7)           在emitErrorNT(net.js:1277:8)           at _combinedTickCallback(internal / process / next_tick.js:80:11)           at process._tickCallback(internal / process / next_tick.js:104:9)         name:'SequelizeConnectionRefusedError',         消息:'connect ECONNREFUSED 127.0.0.1:3306',

我不知道为什么会这样。

以下是我的配置设置。我只更改了这篇文章的pass和db,我在连接时使用了正确的凭据。

config.sql = {
    host: 'sql2012dev',
    database: 'db',
    user: 'sa',
    password: 'pass'
}

这是我的联系。

const sequelize = new Sequelize(config.sql.database, config.sql.user, config.sql.password, {
  host: config.sql.host,
  dialect: 'mssql',
  port: '1433',
  driver: 'tedious',
  dialectOptions:{
   instanceName: MSSQLSERVER 
  },
  define: {
    timestamps: false
  },
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },
})

我可以使用管理工作室远程连接到它。命名管道和SQL浏览器已启用。

我还必须运行npm mysql才能让应用程序启动。

以下是我的依赖项以防万一

  "dependencies": {
    "async": "2.1.5",
    "body-parser": "1.17.1",
    "client-sessions": "0.7.0",
    "cookie-parser": "1.4.3",
    "crypto": "0.0.3",
    "debug": "2.6.2",
    "ejs": "2.5.6",
    "express": "4.15.2",
    "helmet": "3.5.0",
    "jquery": "3.1.1",
    "moment": "2.17.1",
    "morgan": "1.8.1",
    "mssql": "^4.0.4",
    "nsp": "2.6.3",
    "sendgrid": "4.8.0",
    "sequelize": "^3.14.1",
    "tedious": "^2.0.0"
  }
}

2 个答案:

答案 0 :(得分:1)

您是否更改了mysql的默认端口。如果没有,请在配置中使用默认端口。

const sequelize = new Sequelize(config.sql.database, config.sql.user, config.sql.password, {
  host: config.sql.host,
  dialect: 'mssql',
  port: '3306', //-------------> change port here
  driver: 'tedious',
  dialectOptions:{
   instanceName: MSSQLSERVER 
  },
  define: {
    timestamps: false
  },
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },
})

还要确保您的服务器已启动并可从运行应用程序的计算机访问。

答案 1 :(得分:0)

不确定这笔交易是什么,但我现在可以连接。我想知道变量的定位是否有问题。

LOAD_GEN_DATAFILE = 'C:\Users\RoszkowskiM\Desktop\Data_2016.csv' # CSV File to Read

with open(LOAD_GEN_DATAFILE) as csvfile:
     reader = csv.DictReader(csvfile)
     mydict={}
     for row in reader:
         Year=row['Year']
         Busnum=row['Busnum']
         Area=row['Area']
         Power=row['Power']
         TLA=row['TLA']
         Location=row['Location']
         Yearlink=row['Yearlink']
         From=row['From']
         To=row['To']
         Max=row['Max']
         Min=row['Min']
year = raw_input("Please Select Year of Study: ") 
print("\n")

commands = ["Millwood-Buchanan", "Astoria-East-Corona", "Bronx", "DUNWOODIE-North-Sherman_Creek",
        "Vernon", "Greenwood-StatenIsland","West_49th","East_13th","Staten_Island","East_River",
        "East_View","DUNWOODIE-SOUTH","Corona-Jamaica","Astoria-East-Corona-Jamaica",
        "Astoria-West-Queensbridge-Vernon","Astoria-West-Queensbridge"]
max_columns = 50

for index, commands in enumerate(commands):
    stars_amount = max(max_columns - len(commands), 0)
    row = "# {} {}({})".format(commands, "." * stars_amount, index + 1)
    print(row)

 location=raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ")
 print("\n")

if year==Year and location==Location:  
   mydict=[Busnum,Area,Power]

print("Here are all the busses at that location for that year and the new LOAD TOTAL: ")
print("\n")

   for Busnum,Area,Power in mydict:
    Power= float(scaled_power)
    Busnum = int(busnum)
    print('Bus #: %d\t' % Busnum ,'Area Station: %s\t'% Area,'New Load Total: %d MW\t' % Power)