简体   繁体   English

如何在Windows Phone 8.1中连接MS SQL数据库

[英]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. 我会提到两种方法 - 就像我现在所知道的那样。

  1. 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: 以下是可以帮助您的参考资料:

  2. 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.

相关问题 将Windows Phone 8.1 Store应用连接到现有的Azure SQL数据库 - Connect a Windows Phone 8.1 Store App to an Existing Azure SQL Database 如何在Windows Phone 8.1中处理预填充的数据库 - How to handle prepopulated database in Windows Phone 8.1 如何连接windows phone app使用存储在sql azure中的数据库 - How to connect windows phone app to use database stored in sql azure 如何使用Windows Phone 8连接到服务器上已托管的SQL Server数据库 - How to connect to a SQL Server database already hosted on server with windows phone 8 SQL Server的Windows Phone 8.1 Silverlight应用程序中的本地数据库 - Local database in Windows Phone 8.1 Silverlight application from SQL Server Windows Phone 8.1 Silverlight的数据库 - Database for Windows Phone 8.1 Silverlight 如何将Windows Phone 8.1应用程序连接到Fabric Crashlytics? - How to connect the Windows Phone 8.1 app to Fabric Crashlytics? Windows Phone 8.1 Sql连接 - Windows Phone 8.1 Sql connection Windows 8.1服务无法连接到SQL Server数据库 - Windows 8.1 service can't connect to SQL Server database 如何使用数据库更新Windows Phone 8.1中的辅助图块 - How to update a secondary tiles in windows phone 8.1 using database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM