Accessing a database directly from JavaScript is generally considered very risky, as it will give your clients direct access. It is considered much safer to use a server side language such as PHP, Java, .Net, etc... However, assuming you are aware of the risks, and it isn't a concern, this post goes into good detail on how to set up a database connection to a SQL server through JavaScript
How to connect to SQL Server database from JavaScript in the browser?
In terms of then generating a QRCode, this post offers a few good APIs for generating QR codes in Javascript.
javascript API for generating QR codes
Hope this helps!