How do I connect to SQL Azure from NodeJS/Tedious?

◇◆丶佛笑我妖孽 提交于 2019-12-10 22:09:06

问题


I have a SQL Azure database that I'm trying to connect to from a NodeJS application running in an Azure Linux VM. Everything works fine when I'm on a local SQL Database/and local machine for NodeJS. However, when I run from my vm, I get the following output (My trace output plus the Tedious debug event):

connected to XXXXXXX.database.windows.net:1433
State change: Connecting -> SentPrelogin
State change: SentPrelogin -> SentLogin7WithStandardLogin
connection to XXXXXXX.database.windows.net:1433 closed
State change: SentLogin7WithStandardLogin -> Final
Writing CSV files....
connection to XXXXXXX.database.windows.net:1433 closed
State change: Final -> Final
All Done!

The problem is that no error is ever raised, but the connection seems to be automatically closed.

Any thoughts on what might be happening here or how I can get to an actual error?


回答1:


Ok - solved it thanks to this thread

There were 2 issues:

  1. SQL Azure requires encrypted connections, so you need encrypt:true in the connection options
  2. the userName configuration option requires the database-qualified name (e.g. user@XXXXXX.database.windows.net)

Just in case anyone else runs into this :)




回答2:


I encountered a 3rd issue that I thought was worth sharing. Due to some firewall/isp/port/etc issues, I had to set up a local SQL instance to debug with.

The local instance of SQL Server 2014 worked when I used a 'database' parameter under the main tree. However, the Azure instance would only take the 'database' parameter if it is under 'options'.

"sqlserverConfig": {
    "userName": "SomeUser@someazureserver.database.windows.net",
    "password": "SomePW",
    "server": "someazureserver.database.windows.net",
    "options": {
        "encrypt": true,
        "database": "SomeDatabase"
    }
  }

For me, the symptom that I observed was that I was connecting to the master db by default - So my stored procedures weren't found, etc. Very frustrating. Hope this helps someone.



来源:https://stackoverflow.com/questions/16047905/how-do-i-connect-to-sql-azure-from-nodejs-tedious

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!