I have been successfully using an ASP.NET application to connect to a SQL Server 2016 database. However, I now have a new task of incorporating Javascript into the code in order to retrieve data from the database and present it to the user. I am aware of the security risks associated with directly connecting to the database through Javascript, as it exposes sensitive information like usernames and passwords. Therefore, I am seeking a safer alternative that involves having the Javascript code call server-side code to fetch the data (which is stored in the database as JSON). While I understand that AJAX is used for this purpose, I am unsure of how to obtain the connection string required for AJAX to function. I have heard about Node.js, but given that we already have a server in place, I am feeling a bit perplexed. Any advice on this matter would be greatly appreciated!
On a side note, I have come across an explanation on why a direct connection is not advisable here. Although the top answer suggests using server-side languages like PHP, Java, or .NET for connecting to a SQL server, they did not elaborate on how to achieve this specifically with .NET.