I am building a react native app for mobile on my MacBook. I want to connect MS SQL server where is installed in VMware Fusion virtual machine. How can ı connect my MS SQL server on my MacBook?
2 Answers
You can't. Or more appropriately, you shouldn't. React is a front end library and it should connect to a backend service such as REST API which then connects to MS SQL database.
The reason why you shouldn't is simple. Front-end libraries have all their code running in the client's browser which allows the user to view the source. If the user can view the source and there is a database connection in the source, he'll be able to connect directly to your database.
By using a REST API, you can hide all database connection information on your server to which the user has no access.
Sample tutorial: https://dzone.com/articles/aspnet-core-crud-with-reactjs-and-entity-framework
2 Comments
A little too late but just in case someone trying to find a way to directly access an MSSQL database from his react-native app like I did.
https://github.com/davidstoneham/react-native-mssql
I still agree with @bobek's answer that it isn't the best approach but handy when you don't want to create an API layer and have direct access to the database.