0

I am trying to connect an Azure Function to a SQL-Database that I also created in Azure. Sounds pretty simple and Microsoft even has a pretty good POC tutorial for it. However, in my case the Azure Function is dropping "entryPoint" errors that I am not able to resolve.

I checked some other stackoverflow discussions (Can't connect Node.js server to Azure SQL Database) and googled the hell out of it. Unfortunately it seems like none of this is helping. I updated the "function.json" to set my entryPoint as shown below.

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

My index.js code is a very trivial try to connect to the database and tell me about the success.

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");  
    });

Normally this should connect to the database and print a "Connected" to the console but somehow it shows this error:

[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

Hopefully this is enough information to understand my problem. The database has no special firewall etc. at the moment. Besides it seems like the code snippet isn't even able to get in touch with the firewall. Thanks in advance.

0

1 Answer 1

0

I believe you haven't exported your function properly based on the error message - basically missed the module.exports line.

I guess your code looks something like this

...

async function TediousTest() {
...
}

If so, just add this line to the end

module.exports = TediousTest;
Sign up to request clarification or add additional context in comments.

4 Comments

Does this mean that I clip my whole code within "async function XXX(){}"? And afterwards in the end just simply drop the modul.exports line.
Yes. You can directly have module.exports = async function(){ ... too if you'd like
You made my day, thanks a lot. This works perfectly fine. Is there any documentation from Microsoft or some NodeJS stuff that explains this circumstances? I mean something that explains the necessity to do it like this.
The export line is not really specific to Azure Functions and is a standard way to work with modules in NodeJS in general. Nonetheless, you can get more details on how to work with JavaScript in Azure Functions from this official doc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.