Solved

Best Practice for Data Application Development - TableAdapters vs. Stored Procedures

Posted on 2014-07-24
6
693 Views
Last Modified: 2014-07-28
Hello,

I am frequently asked to develop solutions using a SQL Server database and VB.NET (Visual Studio 2010).  Table adapters seem to work fine for application development on datasources when the datasource is relatively stable.  

However, when tables are constantly being modified, it seems like I'm spending as much time reconfiguring adapters, rerunning configuration Wizards, messing around with tableadaptermanagers, dataset designers, query builders, binding sources, databindings, binding navigators, and datasets.  Bluagh!  Microsoft gets an 'F' for creative naming.

So far, the only way I can see for the app to recognize a new or modified field is for me to remove a tableadapter from the Dataset designer, and then add it back in again.  But this causes problems, sometimes, with relationships between tables.

I'm by no means a "seasoned" programmer - and do so only sporadically.  But it seems to me for development of applications with volatile data schemas that it might be easier to just use straight stored procedures in SQL and call them using the System.Data.SQLClient methods, like:

        Dim cn As New SqlConnection(My.Settings.DBConnectionString)
        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Connection = cn
        cmd.CommandText = "DeleteARecord"

        cmd.Parameters.Add("@RowID", SqlDbType.Int)
        cmd.Parameters("@RowID").Value = intDeleteRecord

        Try
            cn.Open()
            Dim intRowsAffected As Integer = cmd.ExecuteNonQuery
            Me.ClientTableAdapter1.Fill(Me.DBDataSet.Client)

            MessageBox.Show(intRowsAffected.ToString & " Rows Deleted.", "Success")


        Catch ex As Exception
            MessageBox.Show(ex.Message)


        End Try
        cn.Dispose()
        cmd.Dispose()

Open in new window


Plus, in the end, the heavy work is on the server, and I'm guessing the applications are significantly lighter.

Any advice?
0
Comment
Question by:kmoloney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 28

Assisted Solution

by:sammySeltzer
sammySeltzer earned 250 total points
ID: 40217161
Ever since I started developing apps, I was advised that it is better to use stored procedures for at least two good reasons.

1, when changes are needed to the sql, it is better to make the changes only one place and that is at the stored procedure level.

This help reduce not just development time but errors that could result from tinkering with several of your app pages.

2, Second reason is performance. With Stored procedures, records are cached it making it faster to call the stored procedure, rather than hit the db quite often.

So, given the choice between table adapters and stored procedures, the choice is easy for me.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40218584
I agree with SammySeltzer, and personally, I do most of my database access through Stored Procedures, either handling the result in DataTable objects or my own classes.

But if you want to stick with something that is closer to .NET and simpler to use, I would explore Data Entities (Entity Framework). This is the way Microsoft has been going since around 2010. They are easier to maintain up to date that TableAdapters.

TableAdapters were developed in one of the first w versions of .NET and have not evolved much since. LINQ came after them, and the Entity Framework came after LINQ.

Although technologies such as the TableAdapters and LINQ are still supported, this is mainly for reasons of backward compatibility. The Entity Framework is all you hear nowadays at Microsoft. It appears everywhere. The first line of the documentation on the subject states it very clearly: The Entity Framework is Microsoft’s recommended data access technology for new applications.
0
 
LVL 2

Author Closing Comment

by:kmoloney
ID: 40222922
Without going thru tons of docs, how (or is) the entity framework supported in VA 2010?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 2

Author Comment

by:kmoloney
ID: 40222923
BTW, great comments both.  :).
0
 
LVL 40
ID: 40223358
What is VA?

If it's a typo and you meant VS, then yes, the entity framework is supported in 2010. If my memory is good (which it is not always the case after working with 11 versions of Visual Basic), data entities appeared in VS 2008 SP1.
0
 
LVL 2

Author Comment

by:kmoloney
ID: 40225417
Thanks, and yep, it was a typo.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question