TheIdiot
TheIdiot

Reputation: 307

Connect Windows Phone and Windows 8 apps to SQL Server

What is the best method to connect a Windows Phone app or Windows 8 app directly to an SQL Server?

The apps must not use a proxy/IIS etc. and was hoping to connect directly using SQL like with normal desktop applications.

Thanks.

Upvotes: 1

Views: 9169

Answers (1)

Jan Hommes
Jan Hommes

Reputation: 5152

You can't directly connect to a SQL Server, because of the Metro-Apps-Sandbox concept. They only can comunicate with a server through a service. The only way around this limitation that I know of is a SQLite integration into Windows 8 Apps.

In my opinion the best way (if you use Visual Studio) is the EntityFramework. It seems a bit complex at the beginning, but the ORM really helps while developing (less mistakes through intellisens, more security against injections). Then you wrap it up into a WCF Data Service and you are ready to use any SQL-Database in your application.

The Entity Framework enables developers to work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern themselves with the underlying database tables and columns where this data is stored. With the Entity Framework, developers can work at a higher level of abstraction when they deal with data, and can create and maintain data-oriented applications with less code than in traditional applications

You can decide between two ways:

  1. Model first - Design your DB inside Visual Studio or SQL Server Management Studio
  2. Code first - Design your DB based on Classes

However there are some downsides:

  • If you use Windows Azure you cannot use n:m relationship direct because of some restrictions to Azure Databases.
  • You need to call the database async for Windwos 8 development. Therefore, there are always some confusing between the old client side use of EF and the new use in Windows 8.

Here is the Page of the EF-Project. You should start there to dive into it.

Upvotes: 4

Related Questions