• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Faster way of Inserting/Deleting and amending in my code

Hi there I am desperate for help!!

My finished app is being used by up to 80 people.  It is VB.net 2005 using a msAccess database (Office 2003).  The performance really slows down to a crawl when the database is opened manually(which isn't a big problem as this is rare) and when there is a record lock (this is the main problem as there is a record lock everything someone saves, deletes or amends).  Everyone is updating the same tow tables in the database so it is having a lot of record locks and people have to wait around when they click save.  I am using sql update statement using an executenonquery method.  Is there a better way to update that will speed up the performance?  Any advice on performance for this code would be very, very gratefully received.

I am doing a couple of execute scalar to get values out of the table to check what needs updating then using the following code to update the first table:

    Dim sWeekNo As String = Format(SelectedDate.Date, "MM/dd/yyyy")
                sqlStr = "INSERT INTO tblTimeWeekly (StaffID, ChargeRate, WeekNo )VALUES (" & zStaffID.Text & ", " & zRate.Text & ", #" & sWeekNo & "#)"
                myCmd = New Data.OleDb.OleDbCommand(sqlStr, conTRS)

                Try
                    If myCmd.Connection.State <> ConnectionState.Open Then myCmd.Connection.Open()
                    x = myCmd.ExecuteNonQuery()
                    If conTRS.State = ConnectionState.Open Then conTRS.Close()
                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                    Cursor = Cursors.Arrow 'Stop hourglass
                End Try

and this code to update the second table:

            '........................................
            'Get the TimeID from tblTimeWeekly
            '........................................
            Dim TID As String
            Dim StaffID As Integer = zStaffID.Text
            TID = TimeID(searchDate, StaffID)
            '****************************************
            '  INSERT INTO tblTimeDaily:
            '****************************************

            If miWeeklyView.Checked = True Then
                If chkNarrative.CheckState = CheckState.Checked Then
                    sqlStr = "INSERT INTO tblTimeDaily (TimeID, SuffixID ,Units, CIndex, Narrative)VALUES (" & TID & ", " & cbxSuffix.SelectedValue & "," & iUnits & ", " & cbxClient.SelectedValue & ", '" & Trim(txtNarrative.Text) & "')"
                Else
                    sqlStr = "INSERT INTO tblTimeDaily (TimeID, SuffixID ,Units, CIndex )VALUES (" & TID & ", " & cbxSuffix.SelectedValue & "," & iUnits & ", " & cbxClient.SelectedValue & ")"
                End If
            ElseIf miDailyView.Checked = True Then
                Dim myDay As Date = MonthCalendar1.SelectionStart.Date
                Dim sDate As String = Format(myDay, "MM/dd/yyyy")
                If chkNarrative.CheckState = CheckState.Checked Then
                    sqlStr = "INSERT INTO tblTimeDaily (TimeID, SuffixID ,Units, CIndex, TStart, TFinish, dDate, Narrative)VALUES (" & TID & ", " & cbxSuffix.SelectedValue & "," & iUnits & ", " & cbxClient.SelectedValue & ", '" & cbxFrom.Text & "', '" & cbxTo.Text & "', #" & sDate & "#, '" & Trim(txtNarrative.Text) & "')"
                Else
                    sqlStr = "INSERT INTO tblTimeDaily (TimeID, SuffixID ,Units, CIndex, TStart, TFinish, dDate)VALUES (" & TID & ", " & cbxSuffix.SelectedValue & "," & iUnits & ", " & cbxClient.SelectedValue & ", '" & cbxFrom.Text & "', '" & cbxTo.Text & "', #" & sDate & "#)"
                End If
            End If

            myCmd = New Data.OleDb.OleDbCommand(sqlStr, conTRS)

            Try
                If myCmd.Connection.State <> ConnectionState.Open Then myCmd.Connection.Open()
                x = myCmd.ExecuteNonQuery()
                If conTRS.State = ConnectionState.Open Then conTRS.Close()
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
                Cursor = Cursors.Arrow 'Stop hourglass
            End Try



0
Cherryex
Asked:
Cherryex
  • 3
  • 2
  • 2
  • +2
2 Solutions
 
TimCotteeCommented:
Hi Cherryex,

The simple answer is to use something like sql server instead of access. With around 80 concurrent users, access is going to struggle. There is probably nothing much you can do to your code itself to improve things, you simply need to use a back-end database that is more capable of dealing with this number of users than access is.

Tim Cottee
0
 
LordWabbitCommented:
And if licensing costs are an issue I would suggest using a Firebird database server since it's free, has no limitations to speak of and is quite robust.
0
 
foobarrCommented:
vb.net 2005 should have come wiht a sql 2005 express edition

you could possibly load that up with your tables and see your performance on it
0
Industry Leaders: 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!

 
lojk.Net and Infrastructure ConsultantCommented:
in the abscense of going fully over to sql, you could write a small sockets application to pass the execute commands to a sockets server application that could run the execute commands for you remotely and in a sequential fashion. That *may* speed it up slightly but sql really is the way to go...
0
 
CherryexAuthor Commented:
Hi all,

Thank you for the responces.  It has been so busy since it went live that I haven't had a second to do anything else.  Not what I wanted to hear but looks like SQL is the way to go.  The only problem is that I have never used SQL and don't have a clue where to start.  We do have SQL server enterprise edition all ready to be set up with it's own server.  Could anyone recommend any articles or tutorials that could get me started converting Access back end to SQL?
0
 
lojk.Net and Infrastructure ConsultantCommented:
Depending on the complexity of your access DB Its pretty much as simple as using the DTS (Data Transformation Services) to import the data and changing all of your connection strings in your app... Ideally you should use the SQLClient from. net but if you are desperate to get it done quick (at a slight performance hit) you should be able to still use the existing OLEDB one but use sql connection string until you have time to finish migrating the code.

The worst thing you might run into is "Select * from Something where Field Like ... " commands will need to be changed slightly.

Check out the SQL Server Books Online at MS (Http:\\msdn.microsoft.com) and consult the apprpiate Section in your VS IDE MSDN, woudl recommend starting with 'Choosing Your Data Source' or similar
0
 
TimCotteeCommented:
Cherryex,

Access does have a built-in SQL upsizing wizard, this will make a reasonable stab at creating the tables etc from your access database on sql. As lojk says, you should be able initially to use the oledb objects with a different connection string though the sql specific objects will be slightly faster in the long run.

Tim
0
 
CherryexAuthor Commented:
Thank you.  That you have all been a great help.
0
 
lojk.Net and Infrastructure ConsultantCommented:
Oh one last thing... Access has a Access Data Project (.adp) that allows you to present a sql DB inside the access front end. Im not sure but you may be able to set up an adp and access that through code, in either case i find it a much easier way of viewing SQLDB tables than the enterprise manager or query analyser.
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!

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now