Solved

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

Posted on 2014-07-24
6
655 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

774 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