我试图将Azure函数连接到我也在Azure中创建的SQL数据库。听起来很简单,Microsoft甚至为此提供了一个不错的POC教程。但是,在我的情况下,Azure函数会丢弃我无法解决的“ entryPoint”错误。
我检查了其他一些stackoverflow讨论(Can't connect Node.js server to Azure SQL Database)并用谷歌搜索。不幸的是,这似乎无济于事。我更新了“ 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
希望这是足够的信息,可以理解我的问题。该数据库目前没有特殊的防火墙等。此外,似乎该代码片段甚至无法与防火墙联系。预先感谢。
答案 0 :(得分:0)
我认为您尚未根据错误消息正确导出函数-基本上错过了module.exports
行。
我猜你的代码看起来像这样
...
async function TediousTest() {
...
}
如果是这样,只需将此行添加到最后
module.exports = TediousTest;