簡體   English   中英

Node.js的Azure函數無法訪問SQL數據庫:入口點問題?

[英]Azure Function with Node.js can't access SQL database: Entry point problem?

我正在嘗試將Azure功能連接到我也在Azure中創建的SQL數據庫。 聽起來很簡單,微軟甚至還有一個非常好的POC教程。 但是,在我的情況下,Azure功能正在丟棄我無法解決的“entryPoint”錯誤。

我檢查了一些其他stackoverflow討論( 無法將Node.js服務器連接到Azure SQL數據庫 )並用谷歌搜索出來。 不幸的是,這似乎沒有任何幫助。 我更新了“function.json”以設置我的entryPoint,如下所示。

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "access": "listen",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "entryPoint": "index",
      "direction": "out",
      "name": "res"
    }
  ]
}

我的index.js代碼是一個非常簡單的嘗試連接到數據庫並告訴我成功。

var Connection = require('tedious').Connection;  
    var config = {  
        userName: 'XXXX',  
        password: 'XXXX!',  
        server: 'XXXX.database.windows.net',  
        // If you are on Microsoft Azure, you need this:  
        options: {encrypt: true, database: 'XXXXX'}  
    };  
    var connection = new Connection(config);  
    connection.on('connect', function(err) {  
    // If no error, then good to proceed.  
        console.log("Connected");  
    });

通常這應該連接到數據庫並打印到控制台的“已連接”但不知何故它顯示此錯誤:

[Error] Executed 'Functions.TediousTest' (Failed, Id=XXXXXXX)
node exited with code 1
 [error] Worker was unable to load function TediousTest: 'Unable to determine function entry point. If multiple functions are exported, you must indicate the entry point, either by naming it 'run' or 'index', or by naming it explicitly via the 'entryPoint' metadata property.',[error] Worker XXXXXX uncaught exception:  ReferenceError: executeStatement is not defined

希望這是了解我的問題的足夠信息。 目前數據庫沒有特殊的防火牆等。 此外,似乎代碼片段甚至無法與防火牆取得聯系。 提前致謝。

我相信你沒有根據錯誤信息正確導出你的功能 - 基本上錯過了module.exports行。

我想你的代碼看起來像這樣

...

async function TediousTest() {
...
}

如果是這樣,只需將此行添加到最后

module.exports = TediousTest;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM