0

I understand this is not best practice but I am operating within a limited realm and, as far as I can tell, this is the only solution to this problem.

I am trying to connect to an MS-SQL database both to get data and to put data onto the database. I cannot seem to do it through JavaScript.

ActiveXObject is, from my understanding, now depreciated so that is not working, which eliminates every functional solution that I could find recommended in the past.

Please note: I am not a web developer and I have no access to any of the standard web development tools for this task.

1
  • Get a back-end procedure! If you are not a web developer then you should be asking be right way to connect MY-SQL and apply best practice programming. ActiveXObject is bad practice, depreciated or not. Commented Aug 1, 2019 at 8:19

2 Answers 2

1

This is the question has been asked multiple times in various forums - Can my client-side Javascript (running in a browser) connect to a database server and fetch data?

The short answer is - not recommended in general, not feasible without breaching security and without using outdated technologies. Let us dig into it.

It is possible to connect to remote database from a browser using outdated technologies

There are two pieces of technologies from Java and .Net worlds - Applet and ActiveX that run on the browser and can communicate to a remote database. The Java Applet is hardly used by anyone nowadays and browsers are stopping to support it. ActiveX is discontinued by Microsoft in their newer browser Edge. So, you have to enforce your target users to use old insecure browsers if you want to go with these options.

Do not use this.

Use databases embedded in the browser and sync with a remote database

You may use the database locally available in the browser and perform all read/write operations. Periodically sync this database with a remote one. Here are the options:

  • MongoDB and use change stream to sync with a remote MongoDB
  • PouchDB and sync with a remote CouchDB or even a MySQL database

Use this only for offline storage temporarily in the browser.

The traditional and secure approach to connect to a remote Database

Use a server-side technology to develop an app that your client-side code (Javascript, HTML) talks to. The app may provide RESTful APIs to interact from the client-side. Then the app that is running in a web server connects and interacts with the database. There are plenty of server-side technologies such as Java, PHP, Python, NodeJS (Javascript based), .Net, etc. to develop your server-side app.

Go with this option.

Sign up to request clarification or add additional context in comments.

Comments

0

Well javascript is a client side scripting where as your database runs on a server. So firstly you cannot connect to a database for executing any query from client side i.e javascript and also you need to setup a server side service which can connect to the database and execute the query and give you the result at the client side. You can refer any client-server architecture for this on the web.

Comments

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.