xcode 如何使用swift连接sql server
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36055620/
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
How to connect sql server with swift
提问by Nouf_KH
I'm working now on an application for iOS (using swift), the database is already exist in SQL Server. How I will use it and connect with it? Do i need a web service to do that?
我现在正在开发一个适用于 iOS 的应用程序(使用 swift),该数据库已经存在于 SQL Server 中。我将如何使用它并与之连接?我需要一个网络服务来做到这一点吗?
thanks all .
谢谢大家。
回答by DaKnOb
It is recommended to use a web service since having the application talk directly to the database means you need to include the SQL Credentials in the binary and anyone with a copy of the application can get them and do whatever they wish in the database. From a security point of view, this is bad.
建议使用 Web 服务,因为让应用程序直接与数据库对话意味着您需要在二进制文件中包含 SQL 凭据,任何拥有应用程序副本的人都可以获取它们并在数据库中执行任何他们想做的事情。从安全的角度来看,这很糟糕。
The correct approach is to have a web server which will host an "API" -- a web application that will receive HTTP requests from the app and translate them to database queries and then will return the response in another format, such as JSON.
正确的方法是拥有一个 Web 服务器来承载“API”——一个 Web 应用程序,它将接收来自应用程序的 HTTP 请求并将它们转换为数据库查询,然后以另一种格式返回响应,例如 JSON。
However, you need to be careful. This web services must use HTTPS and must first validate the input in order to protect against attacks such as SQL Injection.
但是,您需要小心。此 Web 服务必须使用 HTTPS 并且必须首先验证输入以防止诸如SQL 注入之类的攻击。