开发者

Query SQL Server Database from native iOS Application

I am working on an in-house, iOS app that will need r开发者_开发知识库ead-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?


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.


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/


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!


There was a SQL ISAPI extension as part of SQLXML, but I think it has been deprecated: http://msdn.microsoft.com/en-us/library/aa226559%28v=SQL.80%29.aspx

This was effectively a pre-built, and relatively open, web service - so I'm not sure this counts as a direct connection.

You could also check out http://odbcrouter.com/Main

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜