3


I have a windows form application(c#) and an asp.NET web application which both access Sql Server database. I want to centralize the database access. Which metedologies should i follow? What is the common approach to this issue?

  • Writing DAL and Model Libraries and using them in both application?
  • Writing WCF service including DAL model and using this service with both applicaiton?
  • None of the above?

Can you give me any idea?
Thank you.

5 Answers 5

2

I would go with the WCF approach. Keep in mind that when (not if, when) you have to make changes that pertain to one app, but not the other (yet), you will have to account for that in the common layer, so using interfaces may make your life a little easier.

Sign up to request clarification or add additional context in comments.

Comments

1

The cleanest way is to wrap the DB with a WCF services.

If you don't write large amounts of data in one go you can use a WCF Data Service; this directly wraps an Entity Framework model and you can configure access to tables and methods in various ways.

What you want is to have one place where the DB is accessed, so that if there is an issue, you can fix it in one location, for instance.

Furthermore, if you want to log all calls to a particular table, for instance, the only way to make sure that will be done is by centralizing all calls to the DB this way and not allow anybody direct access to the DB.

Wrap the service, then keep the connection string secret.

1 Comment

Hi Roy. I will search for WCF Data Service in details. It may be useful.
0

I think using the SOA approach is really better (WCF or WebServices with a DAL layer) because this way you don't need to publish your DAL dll with the Windows Forms exe. Then, all changes to your data model will automatically happens to your both UI clients.

Remember that this can cause its own problems:

  • Concern with security so that your Services cannot be accessed directly by URL, allowing someone to run your methods.

  • Concern about maintenance, because changes in data layer that needs to affect only one interface will be more difficult to control and needs to be better planned before (with the creation of new methods specific to certain intercace).

  • Decrease in performance, because the HTTP access is always more costly than direct communication with a dll.

  • Risk of lack of communication with the server, something that is expected to ASP.NET but requires additional concerns in the Windows Forms client to behave properly in these cases.

1 Comment

Thanks Erick. Using SOA approach seems more professional but I should consider about performance and security as you mentioned.
0

Option 1 seems simpler and I would do the same.
Option 2 with WCF will add additional code to your product and hence maintenance. Also this would mean an additional layer as well.

Comments

0

Corporate programmers like the second option (WCF service including DAL).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.