Dimitri
Dimitri

Reputation: 7013

What is suggested way of working with remote DB in WPF application

I have a task to create a desktop version of our web app that will be distributed to our customers. I decided to go with wpf. The web app is three tier app with dal, bbl and pl. I could reuse a lot of it in my wpf but question is: is it a good idea to allow remote connections directly to sql server (i could compile connection string directly into the app). Or should i go wcf way and access db through a web service (this will require wrapping business metods around with service methods. Additional coding...)? Any input is highly appreciated.

Upvotes: 1

Views: 1720

Answers (3)

Malcolm O'Hare
Malcolm O'Hare

Reputation: 4999

I would HIGHLY suggest using a WCF service. That way you are in control of what is running queries against your database, and it helps with keeping code updated. A great example why remote connections are bad :

Remote Access World

  1. You use a stored procedure GetAnObject
  2. In the process of upgrading your software, you change GetAnObject to return something different
  3. Now all old versions are broken =(

WCF World

  1. You use a stored procedure GetAnObject
  2. In the process of upgrading, you change what it returns
  3. In your WCF you just have to write some code to convert your object into the old one and send to legacy client. New clients are using a different WCF method call.

Also, I personally am not a fan of opening up my SQL server to any joe blow on a pc who can guess the login.

If you publish a version with an error in it, you at least have a chance the error is in the WCF side and therefore don't have to hassle clients with a 'my bad' upgrade. They never have to know where was a problem.

In a perfect world your WCF service and Web app can share a codebase, so you have less to maintain.

Upvotes: 3

hustler
hustler

Reputation: 178

It all depends on what you want. Are you planning to use the DB layer and business layer across applications? If your answer is yes maybe WCF is the way to go.

We have a bunch of apps where we connect to the DB from WPF app directly because we wanted to avoid the extra layer of indirection which WCF adds.

Upvotes: 0

P.K
P.K

Reputation: 19137

My suggestion is to go via a service (WCF or any other). The extra layer of indirection is decoupling which helps a great deal in maintenance and scalability. For example, if you already had a service which your web application used, it would have been much easier for you to just focus on creating WPF UI.

Upvotes: 2

Related Questions