I have a sqlserver database and on scan target object, based on the object scanned, related information should fetch from the sql server database.
So far I am able to scan Target Image and now I need to fetch data from the sql server database.
Please let me know what are the different ways to get the data from sql database to Unity UI using c#.net.
Even though this question is rather old I will point out some facts. First of all if you’re actually working on a game, just forget about accessing SQL databases from your game. Not because it’s not possible, but because in any kind of game domain it’s inherently insecure. You generally access databases through a backend server. So something ilke a php script on a server with a well defined interface, authentication and restrictions.
If this is not about a game project it’s a different story. However here we have to do another seperation. Even though SQL is “kind of” a standardised language, different servers have quite different dialects which are usually not compatible with each other besides the absolute basics. Apart from the language itself, the way how the communication between the SQL server and the client works is totally different for different servers. So there is no generally valid way to connect to an arbitrary database. Each database server has it’s own communication protocol and you need the proper client to connect to it. If you use an MS SQL server, .NET should have you covered, especially with the System.Data.SqlClient namespace. However if you use for example a MySQL database you need a proper connector. You get the .NET connector for MySQL from the community download page. Specifically this one.
Yes in theory there is the ODBC interface which had the idea of providing a uniform interface to databases. And yes, there are usually ODBC drivers for most databases out there. However ODBC is horrible to work with and is kinda outdated. Connecting to a specific database server directly is generally much faster, easier to work with and gives you the full potential of the DB you’re using. That’s what the majority does nowadays.
If you have never worked with databases (either on the designing side or the programming side) I would recommend you take some time to read into the topic. There are so many thing you can get wrong that you should be aware of. It’s generally dangerous to just jump into development with zero experience. So I recommend to read on topics like database normalization and what’s the idea behind it. It’s important to understand why we do normalization, not just how you may approach it. In production you usually never have a DB in the highest normal form but something in between. It’s always a balance between normalization and ease to use and what makes sense in a particular situation. Though there are some “hard rules” you generally don’t want to violate when it comes to database design.
The other important topic you should inform yourself on as a programmer is database security from the client side perspective. Whenever you have any kind of user input you should be aware of potential risks and attack variants and how to validate / sanitize user input.
While the concept of databases it not that complicated, the overall picture can get really complex