2

I'm currently doing a iOS application for school to connect to school mysql database. It should be able to connect to it through the tools on xamarin studio. I tried a lot of different coding to connect the database, but was unable to do so. Is there any tutorial or example code to let me learn on how to do it ?

Thanks for any help!

Hrqls
  • 2,944
  • 4
  • 34
  • 54
zhihao
  • 45
  • 1
  • 2
  • 10
  • Your solution will be found here : http://stackoverflow.com/questions/16830575/connecting-to-mysql-database-with-my-ios-app – Amirhossein Mehrvarzi Mar 20 '14 at 09:28
  • You can try this suggestion on xamarin forum - http://forums.xamarin.com/discussion/4048/mysql-access-for-android-and-iphone-apps – choper Mar 20 '14 at 09:32

2 Answers2

4

Do not connect directly to a database from a mobile app. Doing this requires exposing your database server directly to the web, which is a horrible security risk. The better approach is to use a web services layer to broker the interaction between your client and your server.

http://docs.xamarin.com/guides/cross-platform/application_fundamentals/web_services/

Jason
  • 86,222
  • 15
  • 131
  • 146
  • how do I use web services through xamarin ? I thought of trying it out whether it works first before moving on to web services. Is it possible to connect directly ? – zhihao Mar 21 '14 at 01:00
  • 1
    You use them the same way you consume web services in any .NET app. I posted a link to the Xamarin docs on web services. – Jason Mar 21 '14 at 01:04
  • okay. May I know which works best in my situation? REST, WCF or SOAP ? – zhihao Mar 21 '14 at 01:26
  • 2
    REST is usually simplest. – Jason Mar 21 '14 at 02:34
  • Alright, now what if we actually want to connect directly to a database, for example to make a database management app? This doesn't answer the question, it advises against it. – Zoey Nov 02 '14 at 04:48
0

While people are right and the best way to connect to a database is to use a web service there are some times you want to connect directly and ways to make the connection more secure (ip restrictions on the mysql server).

Here is a plugin with code examples on how to do it:

https://components.xamarin.com/view/mysql-plugin

Be sure to pay attention to the first forum question on errors and how to resolve. You need to include a reference to system.data, I18N, I18N.West in your project and also make a call to the constructor for I18N somewhere in your code.

new I18N.West.CP1250();

ezekiel571
  • 11
  • 2