Question Beginner, c# and database best practices

tryingtolearn

Member
Joined
Mar 13, 2018
Messages
12
Programming Experience
Beginner
All,
It has been years since I've done any Windows programming (edit: probably close to 10-15 years) and I am trying to jump back in. Essentially, I'm starting over and I'm fine with being called a noob. The purpose of this thread is to get some general knowledge to guide me on what I need to research myself.

I am trying to develop a client application for work that will share GPS lat/long with everyone that also has the client app installed.
I come from a stronger background of PHP and MySQL, so I'll probably just create a backend DB on a LINUX server with a simple table.

When researching "C# Database for Beginners", I found something very unusual. Almost every single tutorial shows that the server IP, username, password, etc hard-coded into the program. The program is doing direct connections to a database. Is this the best practice? I feel like I've heard people talking about calling web services to handle these requests and returning the responses in XML.

I know what the application needs to do, and it's very simple, really. But I want to make sure this is done correctly. What is the best method?

Thank you in advance,
Rob.
 
The "best" method depends on circumstances. If a client application accesses a database on the same machine or even on the same network then it may well be appropriate to connect directly to the database. If you're talking about distributed users connecting over the internet though, it is almost certainly the best option to have a service in between. If you build that service in ASP.NET then it will make a direct connection to the database in the same way that a client would, so any data access examples you've read would still be relevant. If you're building the service in PHP or something else, you won't need to write data access code in C#.
 
jmcilhinney,
I sincerely appreciate your response.

If a client application accesses a database on the same machine or even on the same network then it may well be appropriate to connect directly to the database. If you're talking about distributed users connecting over the internet though, it is almost certainly the best option to have a service in between.

If you don’t mind, I need to pick your brain a bit more. To answer your question, the database would be on a remote server, accessible to any number of client machines. I have no idea where to begin searching on how to create a service. While doing my searches I still only find direct connection examples. Again, I won’t be “that guy” and ask for code, but if you’re able to point me in the direction of where to look to research further I would really appreciate it.

I am a bit worried that I can’t find much—I really feel like this would be a more frequent thing. It leads me to believe I am not taking the correct approach.

Best,
Rob
 
Last edited:
If you're looking to build a web service using PHP then that goes beyond the scope of this thread and this site. If you want to build a web service using C# then the preferred way these days is to use Web API. To do that, open the New Project dialogue in VS and select ASP.NET Web Application (.NET Framework) or, if you want to target .NET Core, select ASP.NET Core Web Application. You will then be prompted for the type of application and that is where you choose Web API. Web API is much like MVC except that controller actions return data to be consumed by applications rather than views to be displayed in a browser. VS also allows to you to create WCF services.
 
Back
Top Bottom