Skip to content
Advertisement

How to connect to mssql server synchronously in node.js

All of the examples for using the mssql client package/tedious driver are for async/callbacks/promises but I’m only developing a microservice that will see limited use and my understanding of asynchronous functions is still a bit fuzzy. Here’s what I have for trying to use async/await :

Report generation class:

JavaScript

Then called:

JavaScript

I’m sure this is probably a pretty bad way to accomplish this, so I’m also open to any input on good ways to accomplish the end goal, but I’d still like to know if it’s possible to accomplish synchronously.

Advertisement

Answer

You can’t do it synchronously. Figuring out this async stuff is definitely worth your time and effort.

async / await / promises let you more-or-less fake doing it synchronously

JavaScript

And, unwrap the async function in your proc function, like so:

JavaScript

await and .then are analogous.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement