[英]How to connect MS SQL database in windows phone 8.1
I'm building my first WP 8.1 app and I have some troubles trying to figure out how to connect my app to an existing MS SQL database that I have already made on a server. 我正在构建我的第一个WP 8.1应用程序,我有一些麻烦试图弄清楚如何将我的应用程序连接到我已经在服务器上创建的现有MS SQL数据库。
The problem is there are not many tutorials online showing step-by-step how to achieve this. 问题是没有很多在线教程逐步展示如何实现这一目标。
As I understand, you cannot directly connect to a remote SQL Database from a WP app but you have to create a service that will connect to the database and the WP app will send requests to that service and respond with the data needed. 据我所知,您不能直接从WP应用程序连接到远程SQL数据库,但您必须创建一个将连接到数据库的服务,WP应用程序将向该服务发送请求并使用所需的数据进行响应。
How can I create the service and how do I integrate that service within my app? 如何创建服务以及如何在我的应用程序中集成该服务? Keep in mind that I have never worked with WP apps, nor with any sort of services before, so if you can please make it as simple and straight forward as possible I would really appreciate it.
请记住,我以前从未使用WP应用程序,也没有使用任何类型的服务,所以如果你能尽可能简单直接地做到这一点,我会非常感激。
Thank you. 谢谢。
You cannot directly access SQL Server database from windows phone app. 您无法从Windows Phone应用程序直接访问SQL Server数据库。 You will first need to add a service layer.
您首先需要添加服务层。 I will mention two ways to do so - as I know as of now.
我会提到两种方法 - 就像我现在所知道的那样。
To use WCF service to connect to the database and using LinqToSql to get data from SQL. 使用WCF服务连接到数据库并使用LinqToSql从SQL获取数据。 For this you need to create two projects in the solution.
为此,您需要在解决方案中创建两个项目。 First is the service and second is your app where you will use LinqToSql to query through the service.
首先是服务,第二个是您的应用程序,您将使用LinqToSql查询服务。 Here are the references that will help you:
以下是可以帮助您的参考资料:
To build a webservice using ASP.Net Web Api. 使用ASP.Net Web Api构建Web服务。 Then use Http client in your application.
然后在您的应用程序中使用Http客户端。 Reference that will help you:
参考将帮助您:
Then you can use LinqToSql or EntityFramework to access or query data from the SQL server database 然后,您可以使用LinqToSql或EntityFramework来访问或查询SQL Server数据库中的数据
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.