locked
Best practices way to access SQL Express database with Javascript RRS feed

  • Question

  • User-858993849 posted

    I have an HTML page using Javascript and Jquery, and am wanting to access an SQL Express database.  What are the best practices way of doing it?

    Thanks!

    Thursday, August 29, 2019 2:03 AM

Answers

All replies

  • User197322208 posted

    Usually, you do not access directly the database from Javascript. You should create some sort of WebAPI and access from there. See Learn in this site links.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 29, 2019 4:17 AM
  • User-821857111 posted

    As Andrei said, you should create Web API controllers to communicate with a data access layer on the server, and then use AJAX to fetch and send data as JSON which you can work with using JavaScript/jQuery. 

    You can use Entity Framework, Dapper or plain ADO.NET in your Web API controllers to actually access the SQL Express database. Web API takes care of serialising the data to JSON for you.

    https://docs.microsoft.com/en-gb/aspnet/core/web-api/?view=aspnetcore-2.2

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 29, 2019 7:17 AM
  • User-858993849 posted


    Thanks Mike, it has been a while since I have been back at this, but once again you are the best!

    I assume I should use core for the API, right?  For example, in VS 2017, I would use ASP.Net Core Web Application vs ASP.Net Web Application (.Net Framework).

    Thursday, August 29, 2019 3:15 PM
  • User-821857111 posted

    Yes,  I would recommend using .NET Core for new projects.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 30, 2019 6:31 AM
  • User-858993849 posted

    Is there a favorite sample/tutorial you have?  A full example, pretty easy to follow that steps all the way through?

    Thanks again!

    Friday, August 30, 2019 5:28 PM
  • User288213138 posted

    Hi JAYHAWKER,

    The tutorial link has been provided above.

    Create web APIs with ASP.NET Core

    you can also refer to this link:

    Creating Web API in ASP.NET Core 2.0

    https://www.c-sharpcorner.com/article/create-webapi-with-dotnet-core/

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 2, 2019 10:21 AM
  • User-858993849 posted

    Thanks Sam, that is what I was looking for.

    Monday, September 2, 2019 1:45 PM