How to create two apps which connect to the same database? - c#

Basically what i am trying to do is to create a desktop app and a phone app(for my IT course) which get and insert data into the same database.
First i thought i could use normal db with remote access but i found out that it isn't the best practice (also not all hosting company allows you remote access and when they allow it you have to insert the IP of the machines which will make the requests, and i do not want something like that). So what do i have to do ? I've been searching a lot but i couldn't find nothing. What i'm looking for is some sort of guide to do this because i really have no idea how to do it. Sorry for my bad english and thanks you all.

Sounds like what you need to do is create a web service that both, your mobile and your desktop apps would connect to to save and retrieve data.

Use existing services. I HIGHLY recommend https://parse.com/ . You can accomplish what you need using their service. Their quickstart guides are VERY simple to understand. It supports iOS, Android, .NET(C#) and many more platforms. Also, for what you need, it is free.

Related

Can I connect to database with another language

Hi i have a C# WinForms app. I wrote essential methods on C#. But I need a login form and its not safe since apps like dotpeek can inspect the source code and hack it. Can i communicate with another application that is written in another language (java,c,python etc). I need to send input data from WinForms C# to another app then it should connect to database and check if login succesfull then return a value back to C# WinForms app. Is that possible, how can i implement that? I dont want to write all application in another language since C# has good methods to process images/pixels and gui support with very small memory usage.
I got the point you are trying to make.
One thing to admit is that you can't completely avoid decompiling of apps. C# or C++, no matter anything can be reverse engineered.
If you still need it, a comparatively safer approach is to not put the checking app at the client's machine. Create an API and host the database on a server.
Then initiate just an Http Request to the server from your Windows Forms app.
Then you have the full control of Login API and database. Many applications use OAuth similar to this. Another examples are apps verify it's license using an online API.
You can get a LightSail Windows server in around $10 a month if you want to setup. Try exploring
Your concern is not baseless. C#, or for that matter, any .net language running on the CLR, will be easier to inspect than a language like C or C++.
Having said that, no app will be completely secure, and communicating between apps has its own problems. How does one app verify the other? etc. You can create a web service that would communicate with the database (and communicate with the web service using HTTP or WCF) which would mean your app wouldn't have direct access to the database, but that would only protect the database from your app, it would still allow someone to inspect your app and use the web service, impersonating your app. Also, you would need to host the web service on some web hosting service, and then you would have to trust that service to not inspect your app...
You can reduce the problem by storing the password etc. as byte arrays, but regardless of what you do, I don't know of a way to completely safeguard your app. If a malicious app/actor is on your computer they can inspect your app.
As for your question itself - look into WCF or named pipes (includes a simple example).

How to create a public server in C#

I am a novice programmer. I was trying to learn about networking in C#. I want to know how to create a public server in C#. I tried to search on the internet but I didn't find much. As a public server, I meant to connect to one computer to another from remote or an online server where I can connect from anywhere which is written in C#. I want to know is how to make it and what I need to do that or especially I want the information how can I make one and what I need. I would like to use winform/wpf or console application for the server.(Sorry for my bad English)
There are plenty of resources out there already, you just need to do your research.
A couple notes:
winform/wpf is a technology for desktop programs, with windows and user controls and such. A server has no need for such things.
a server is a server, public or not. Making it public is as simple as making it available at an IP address / domain that is reachable from the internet. This has little to do with implementation.
there are so, so, so many different types of server applications. Some serve websites, others serve databases, and still others just provide raw data in the form of JSON or XML.
I'm assuming since you're just getting started, you're trying to build a web server to serve a website. Here's a tutorial I found by Googling 'c# web server' that seems to get you up and running: https://codehosting.net/blog/BlogEngine/post/Simple-C-Web-Server
Good luck, and remember that SO is a place for technical questions, not a 'how to do a whole thing start to finish' forum :)
I think the keywords you need are
ASP.NET + IIS, for a full fledged server app
HttpListener, for a stand alone server app
The prior is a framework for building a MVC Server application (it also has a subset called WebApi which as the name states is for APIs), and the latter is the class you will need to create a stand alone server application.
In the future, you might want to consider using ASP.NET Core to deploy your application onto linux.
Good luck.

Avoiding request limits

I'm making Windows Phone app in which I could get some data from Riot Games API (League of Legends dev company). It means that I will be sending some requests but there is a limit of those requests. When many users will try to send request app will reach the limit really quick. How to avoid that? On dev forum they said that I should create web server but I don't know how. I have VPS (Linux installed on it).
Web Server is a Requirement
So the TLDR is that you will HAVE to make a web server. Why? Under Riot's ToS you need to make sure your API key is secure. If it is stored in a phone app then anyone could just open your source and use your key.
Riot Security Guidelines: https://developer.riotgames.com/docs/credentials-security
Note that embedding a key in a distributed client application, like a desktop or mobile application, means that your key can be compromised
How
So how do you get around this? Well you need a web server. The server acts as a safe place for you to store your key AND it will act as a means for you to implement rate limiting.
Your phone phone app will only have your GUI/interface (making it lighter to run), and each request you preform will hit your server first, which will in turn hit the Riot API. Meaning your key is only used on your server requests to the Riot API. You can use something simple for your web service like PHP or a heavier framework like .NET. Both have many guides, along with a wide range of other languages.
Tutorials
A quick Google search turned up a few tutorials, here is one that looked ok: http://www.asp.net/web-api/overview/mobile-clients/calling-web-api-from-a-windows-phone-8-application
Note: If you do not own Visual Studio, they have a free "express" version that I recommend and use myself:
https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx
Web server's pretty much all do the same thing as well, so you can look for tutorials on just that for more general information.
Best of luck!

Sms Delivery Recived Detection in Windows Application

I'm using the mCore SMS Library. I'd like to create a windows application and when i receive a delivery message, the application should save that information into a database.
What technology can i use?
Can i use windows services? How can i implement a windows service?
I think there are several questions you are asking so let's them split up a little:
How to save delivery information in a Database File
To solve this problem you first need to know what kind of database you have (MS Sql, Oracle, MySql, etc.) For each of these exists some kind of DbAdapter. For e.g. the MS Sql you can take a look into the .net framework System.Data.SqlClient Namespace.
Can i use Windows Services?
This depends on the availability of your application and on what machine it will run. In a first step you can write it as a normal application. To get it later into a service you can take a look at Walkthrough: Creating a Windows Service Application.
These are only very vague answer, but you only asked very vague. So dive in and if you good any concrete problems come back with a new question. ;-)

N-Tier with C#?

I am looking at writing a WinForms app and getting stumped over what seems to be simple issue.
There is a server and database (SQL Server) Open ports are HTTP, HTTPS
There is a WinForms client. It needs to connect a TCP/IP stream (possibly HTTP, SOAP, REST) to the server.
Sometimes the WinForms client goes off-line and then the WinForms client stores its data in a database.
When the WinForms client goes on-line to server, it synchronizes data to the server, gets all the latest data from the server and updates local database.
How do I do that?
Newbie question
As you've conceded, this question shows you might not know where to begin looking for how to architect this kind of application.
I'd start here: http://msdn.microsoft.com/en-us/library/ms973279.aspx
The offline architecture you've described is a little tougher for a newbie than not supporting this, consider making the application only work online first, then add offline functionality.
Also, if you have a web server you will almost always use HTTP, SOAP and REST are strategies that sit on top of HTTP. I cannot recommend that a new developer look at any server communication using direct TCP/IP.
Edit: Answer to related question - there are tons of ORMs and service builders, not a lot of them have built in support for offline workflow but ODX does, but it might be a bit out of date. NHibernate and any of the projects in the Castle Project are very popular components for what you're looking to do also.
No idea how actively this is still being supported by Microsoft, but you might check out the Smart Client Software Factory, it seems to support offline mode and smart reconnecting like you need.
http://msdn.microsoft.com/en-us/library/ff709809.aspx
You could approach this with a 'Service' mindset - Write a WebService (preferably a WCF service) - that forms the synchronization tier between your Winforms app. and remote database.
So, you would have your
1. Local WinformsApp. with a local database (as functional/lightweight as you want it to be)
2. WebService
3. Remote app./DB
Here are some links to tutorials/resources:
http://www.codeproject.com/KB/architecture/three_tier_architecture.aspx
http://services.community.microsoft.com/feeds/feed/query/tag/n-tier/eq/tag/visual%20basic/eq/and/locale/en-us/eq/and
http://msdn.microsoft.com/en-us/library/bb384570.aspx
http://msdn.microsoft.com/en-us/library/bb384398.aspx
IMHO this isn't usually as simple as it may sound
If you were able to go DB to DB, then SQL replication could be the simplest mechanism for synchronisation.
However, since it sounds like you are using a SOA approach, you might need to look at frameworks which have offline support built in, such as the Ent Lib Composite Application Block and Smart Client Software Factory
You might also look at using Queues (e.g. MSMQ) to accomodate network connectivity problems.
Microsoft Sync Framework (http://code.msdn.microsoft.com/sync) + WCF solution here:
http://code.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=3762
Database synchronisation is not an easy task to get started with, by any means. Good luck.
Generally, you need a local database, or at least a local cache.

Categories

Resources