简体   繁体   English

如何从NodeJS / Tedious连接到SQL Azure?

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

I have a SQL Azure database that I'm trying to connect to from a NodeJS application running in an Azure Linux VM. 我有一个SQL Azure数据库,我正在尝试从Azure Linux VM中运行的NodeJS应用程序连接到该数据库。 Everything works fine when I'm on a local SQL Database/and local machine for NodeJS. 当我在本地SQL数据库/本地机器上运行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? 有关这里可能发生的事情或我如何得出实际错误的任何想法?

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 SQL Azure需要加密连接,因此您需要在连接选项中加密:true
  2. the userName configuration option requires the database-qualified name (eg user@XXXXXX.database.windows.net) userName配置选项需要数据库限定名称(例如user@XXXXXX.database.windows.net)

Just in case anyone else runs into this :) 以防其他人遇到这个:)

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. 由于一些防火墙/ isp / port / etc问题,我不得不设置一个本地SQL实例来调试。

The local instance of SQL Server 2014 worked when I used a 'database' parameter under the main tree. 当我在主树下使用'database'参数时,SQL Server 2014的本地实例工作。 However, the Azure instance would only take the 'database' parameter if it is under 'options'. 但是,如果Azure实例位于“选项”下,则它只会采用“数据库”参数。

"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. 希望这有助于某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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