{"id":3226,"date":"2011-01-14T07:00:00","date_gmt":"2011-01-14T07:00:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/accessing-sql-server-data-from-ios-apps\/"},"modified":"2017-10-30T10:53:24","modified_gmt":"2017-10-30T10:53:24","slug":"accessing-sql-server-data-from-ios-apps","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/accessing-sql-server-data-from-ios-apps\/","title":{"rendered":"Accessing SQL Server data from iOS apps"},"content":{"rendered":"<p>Almost all mobile apps need access to external data to be valuable. With a huge amount of existing business data residing in Microsoft SQL Server databases, and an ever-increasing drive to make more and more available to mobile users, how do you marry the rather separate worlds of Microsoft&#8217;s SQL Server and Apple&#8217;s iOS devices?<\/p>\n<h5>The classic answer: write a web service layer<\/h5>\n<p>Look at any of the questions on this topic asked in Internet discussion forums, and you&#8217;ll inevitably see the answer, &#8220;just write a web service and use that!&#8221;. But what does this process gain?<\/p>\n<p>For a well-designed database with a solid security model, and business logic in the database, writing a custom web service on top of this just to access some of the data from a different platform seems inefficient and unnecessary. Desktop applications interact with the SQL Server directly &#8211; why should mobile apps be any different?<\/p>\n<h5>The better answer: the iSql SDK<\/h5>\n<p><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/blogbits\/robert.chipperfield\/Accessing-SQL-Server-data-from-iOS-apps_CD18\/iSqlArchitecture-SolidBG.png\"><img loading=\"lazy\" decoding=\"async\" class=\"float-right\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/blogbits\/robert.chipperfield\/Accessing-SQL-Server-data-from-iOS-apps_CD18\/iSqlArchitecture-SolidBG_thumb.png\" alt=\"iSqlArchitecture-SolidBG_thumb.png\" width=\"268\" height=\"208\" \/><\/a>Working along the lines of &#8220;if you do something more than once, make it shared,&#8221; we set about coming up with a better solution for the general case. And so the iSql SDK was born: sitting between SQL Server and your iOS apps, it provides the simple API you&#8217;re used to if you&#8217;ve been developing desktop apps using the Microsoft SQL Native Client.<\/p>\n<p>It turns out a web service remained a sensible idea: HTTP is much more suited to the Big Bad Internet than SQL Server&#8217;s native TDS protocol, removing the need for complex configuration, firewall configuration, and the like.<\/p>\n<p>However, rather than writing a web service for every app that needs data access, we made the web service generic, serving only as a proxy between the SQL Server and a client library integrated into the iPhone or iPad app. This client library handles all the network communication, and provides a clean API.<\/p>\n<h5>OSQL in 25 lines of code<\/h5>\n<p>As an example of how to use the API, I put together a very simple app that allowed the user to enter one or more SQL statements, and displayed the results in a rather primitively formatted text field. The total amount of Objective-C code responsible for doing the work? About 25 lines.<\/p>\n<h5>Beta out now &#8211; your chance to give us your suggestions!<\/h5>\n<p>We&#8217;ve released the iSql SDK as a beta on the MobileFoo website: you&#8217;re welcome to download a copy, have a play in your own apps, and let us know what we&#8217;ve missed using the Feedback button on the site.<\/p>\n<p>Software development should be fun and rewarding: no-one wants to spend their time writing boiler-plate code over and over again, so stop writing the same web service code, and start doing exciting things in the new world of mobile data!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Almost all mobile apps need access to external data to be valuable. With a huge amount of existing business data residing in Microsoft SQL Server databases, and an ever-increasing drive to make more and more available to mobile users, how do you marry the rather separate worlds of Microsoft&#8217;s SQL Server and Apple&#8217;s iOS devices?&#8230;&hellip;<\/p>\n","protected":false},"author":169277,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[9084],"class_list":["post-3226","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/169277"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=3226"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3226\/revisions"}],"predecessor-version":[{"id":75147,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3226\/revisions\/75147"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=3226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=3226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=3226"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=3226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}