Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query SQL Server Database from native iOS Application

Tags:

sql-server

ios

I am working on an in-house, iOS app that will need read-only access to a SQL Server with multiple databases. I know the stock answer here is "write some web services", but I'd like a solution that is self-contained. Is there any way to directly connect to a SQL Server database from an iOS application? I'm thinking something like a basic ODBC connection.

I've seen a lot of users asking this question, but very few answers other than "write a web service." Is that really the only way?

like image 848
mbm29414 Avatar asked Jan 14 '11 13:01

mbm29414


3 Answers

A web service is indeed the only way, but Red Gate's written one you can reuse:

http://www.mobilefoo.com/iSqlServerSDK.html

http://labs.red-gate.com/Tools/Details/iSqlSDK

It's not officially released yet, just in beta, so keep in mind that features & prices may change.

like image 162
Brent Ozar Avatar answered Oct 21 '22 17:10

Brent Ozar


Actually the easiest way is to create a MVC 3 or 4 asp.net web application. call the web methods. You don't need any API to pay for.

I use SBJson to serialize domain object and then send the objects as serialized jSOn to MVC 3. It's super easy to do. I even send images with base64, so it's .net compatible.

See my blog post with sample code: http://nickturner.wordpress.com/2012/10/09/107/

like image 20
Nick Turner Avatar answered Oct 21 '22 15:10

Nick Turner


So, after much searching and trial and error, unfortunately the best (only?) way I've found is indeed using Web Services.

Fortunately, Linq to SQL makes the WCF-creation-side incredibly easy. Once I got someone at work to walk me through setting up a Windows web server and adding the web service (and buying access to an online web server), the Windows side was up and ready to go.

I'm still working through all of the syntax stuff on the SOAP interaction side, but keeping my different methods somewhat similar in structure allows me to tinker a little until it works. By this time, I think I've gotten it to work pretty well.

So, both answers I got back were (disappointingly) correct. The only way to interact is through a Web Service. Even the 3rd party solutions they mentioned were really just convenient wrappers around the same type of technology. As it turns out, I'd rather have finer control over the process.

One word of advice: Get a real, external web server. I tried doing this on a non-Server Windows VM on my iMac/MacBook Pro, and it was like pulling teeth! Once I actually got access to an external, full, stand-alone web server, the process was much more streamlined and easy. Do yourself a favor and take that headache out of the equation!

like image 27
mbm29414 Avatar answered Oct 21 '22 16:10

mbm29414