从本机 iOS 应用程序查询 SQL Server 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4691420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:32:03  来源:igfitidea点击:

Query SQL Server Database from native iOS Application

sql-serverios

提问by mbm29414

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.

我正在开发一个内部 iOS 应用程序,该应用程序需要对具有多个数据库的 SQL Server 进行只读访问。我知道这里的标准答案是“编写一些网络服务”,但我想要一个独立的解决方案。有什么方法可以从 iOS 应用程序直接连接到 SQL Server 数据库?我在想一个基本的 ODBC 连接。

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?

我看到很多用户问这个问题,但除了“编写 Web 服务”之外,很少有人回答。这真的是唯一的方法吗?

采纳答案by Brent Ozar

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

Web 服务确实是唯一的方法,但是 Red Gate 编写的方法可以重用:

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

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

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

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.

它尚未正式发布,仅处于测试阶段,因此请记住,功能和价格可能会发生变化。

回答by Nick Turner

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.

实际上,最简单的方法是创建一个 MVC 3 或 4 asp.net web 应用程序。调用网络方法。您不需要任何 API 来支付费用。

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.

我使用 SBJson 序列化域对象,然后将对象作为序列化的 json 发送到 MVC 3。这非常容易做到。我什至使用 base64 发送图像,因此它与 .net 兼容。

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

请参阅我的博客文章和示例代码:http: //nickturner.wordpress.com/2012/10/09/107/

回答by mbm29414

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

因此,经过大量搜索和反复试验,不幸的是,我发现的最好(唯一?)方法确实是使用 Web 服务。

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.

幸运的是,Linq to SQL 使 WCF 创建端非常容易。一旦有人在工作中指导我设置 Windows Web 服务器并添加 Web 服务(并购买对在线 Web 服务器的访问权限),Windows 端就已启动并准备就绪。

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.

我仍在研究 SOAP 交互方面的所有语法内容,但让我的不同方法在结构上有些相似,这让我可以稍微修改一下,直到它起作用为止。到这个时候,我想我已经让它工作得很好了。

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.

所以,我得到的两个答案(令人失望地)都是正确的。唯一的交互方式是通过 Web 服务。甚至他们提到的第 3 方解决方案也只是围绕相同类型技术的方便包装。事实证明,我宁愿更好地控制这个过程。

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!

一个忠告:获取一个真正的外部 Web 服务器。我尝试在 iMac/MacBook Pro 上的非服务器 Windows VM 上执行此操作,就像拔牙一样!一旦我真正可以访问外部的、完整的、独立的 Web 服务器,这个过程就会变得更加精简和容易。帮自己一个忙,把头疼的问题排除在外!

回答by Cade Roux

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

作为 SQLXML 的一部分,有一个 SQL ISAPI 扩展,但我认为它已被弃用: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

您也可以查看http://odbcrouter.com/Main