473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Very slow updating access table using vb.net

19
Hey everyone, I'm having some issues here. I have a large Access .mdb (over 400,000 rows).

What I need to do is, there are 12 columns that need to be reordered (quite literally as simple as if it is XZY, change to XYZ, but the row next to it must ALSO be changed accordingly, as in, WEC to WCE [in other words, however the first row's order was changed, the second row must also be changed in the exact same order]).

Anyways, when counting all of the rows that have the above mistake, there are nearly 300,000 rows affected. I need to write a quick program or web app that can go through, find any row that isn't ordered properly (XYZ) and change it (and the row next to it) to the proper order. Then I need to update the Access database with the new data.

Here is my current code:

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Data
  3. Imports System.Data.OleDb
  4. Imports System.Text
  5.  
  6. Module Module1
  7.     Sub Main()
  8.  
  9.         Dim conn, cmd, adpt, Data
  10.         conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Phasing Devices.mdb")
  11.         cmd = New OleDbCommand("SELECT TOP 500 * FROM phasedetails WHERE devphasing1='YX' OR devphasing1='yx'", conn)
  12.         adpt = New OleDbDataAdapter(cmd)
  13.         Data = New DataSet()
  14.         adpt.Fill(Data)
  15.  
  16.         conn.Open()
  17.         Dim i = 0
  18.         For Each Dr As DataRow In Data.Tables(0).Rows
  19.             Dim id = Dr.Item("ID")
  20.             Dim devphasing1, devorien1, title, title2
  21.             Dim newDevphasing1 As String
  22.             Dim newDevorien1 As String
  23.  
  24.             title = "devphasing1"
  25.             title2 = "devorien1"
  26.             newDevphasing1 = "XY"
  27.             devphasing1 = ""
  28.             devorien1 = ""
  29.             newDevorien1 = ""
  30.  
  31.             devphasing1 = Dr.Item(title).ToString
  32.             devorien1 = Dr.Item(title2)
  33.  
  34.             If Len(devorien1) > 0 Then
  35.                 newDevorien1 = Right(devorien1, 1) & Left(devorien1, 1)
  36.             Else
  37.                 newDevorien1 = ""
  38.             End If
  39.  
  40.  
  41.             Dim objCommUpdate As New OleDbCommand("UPDATE phasedetails SET devphasing1='XY' AND devorien1='" & newDevorien1.ToString & "' WHERE ID=" & id, conn)
  42.  
  43.  
  44.             Try
  45.                 objCommUpdate.ExecuteNonQuery()
  46.             Catch ex As Exception
  47.                 Console.WriteLine("Error!")
  48.             End Try
  49.             Console.WriteLine("Done: " & id & " (2)")
  50.         Next
  51.  
  52.         Console.WriteLine("Completed Successfully...")
  53.  
  54.         'Close the database connection
  55.         conn.Close()
  56.         Console.ReadLine()
  57.     End Sub
  58.  
  59. End Module
  60.  
Now, ignore the query at the moment. I am only doing it for YX to XY to get it working, then I'll expand it for all variations of XYZ that need to be re-ordered alphabetically.

From my own messing around, I've found that removing this line makes everything go tons faster:

objCommUpdate.ExecuteNonQuery()

So I know that it has something to do with updating the database. So can anyone figure out how to speed things up? Right now it takes literally a second for each update, and it is literally impossible to try and get this done for 300,000 rows.
Aug 2 '07 #1
12 4363
Plater
7,872 Expert 4TB
this is something that only needs to happen once though right?
once things are in order you don't have to worry about it?
fire it off on a slow time and let it go.
Aug 2 '07 #2
MGM
19
I already tried having this run overnight and it only completed about 30% of it. It would take about 3 full days for this to get done. If I were to let this run over the weekend, and if something were to go wrong, I wouldn't know about it until Monday, which probably means I'd have to start it all over again.

I need something that can get this done as quickly as possible, preferably a few hours, and no more than a day (so that I can keep track of it on and off over a 24 hour period).

One idea I had is to import this into a SQL Server database, then do the updating there (using an ASP web app or .net app), and then export it back to an Access database. Is this a viable solution or will I run into the same speed issues?

MGM out
Aug 3 '07 #3
Plater
7,872 Expert 4TB
So let me see if I understand this
You have a table like:

A | B | C
------------
1 | 3 | 2
4 | 3 | 6

For example. And you need to go down each row and correct them as to some design.
(for my example I will make them count up)
A | B | C
------------
1 | 2 | 3
3 | 4 | 6

Is that correct? Cause oh-boy would that ever be intensive.
You could try moving it to MSSQL but I don't know how much time that will really even buy you.
You may want to just try and do it section by section. Do it in chunks of 50k entries at a time or something.
If they don't need to be fixed, your time will be greatly reducee I would think.

So If you just keep doing 50k until you think you've gotten them all, then do a scan over the WHOLE thing, the full scan should take way less time because hopefully it won't have to fix any.
Plus, with the 50k entries you'll have the added bonus of only trying to move around a much smaller chunk of data
Aug 3 '07 #4
MGM
19
It's more like this:

A | B | C
------------
1 | 3 | 2
5 | 6 | 4

Needs to turn into this:

A | B | C
------------
1 | 2 | 3
5 | 4 | 6


Notice how the second row changes according to how the first row's order is changed (to numerical)?

And I don't really see how making it into 50k chunks would help, as it would still take the same amount of time to go through and edit all of the rows... except now I have to run the program 6 times to get all 300,000 rows...

MGM out
Aug 3 '07 #5
Plater
7,872 Expert 4TB
Well I don't see much difference in our examples (except that your first coloumn never changed)

And doing it in 50k chunks means you can be around for the result and to see if anything goes wrong.
Aug 3 '07 #6
MGM
19
The ABC are the column names, and the numbers are different (132 to 123, and 564 to 546).

I uploaded it to SQL Server and wrote a quick ASP web page to do the conversion and it seems to do it much, much faster. It'll still take a while, but hopefully not as long. Only problem is, I can only do about 300 rows at a time or else it gives me a Timeout error. Any way to get past this? Would doing it in vb.net be faster?

MGM out
Aug 3 '07 #7
Plater
7,872 Expert 4TB
Is the timeout error an SQL timeout or a webpage timeout?
If it's a webpage timeout, you can throw it in a windows app and be done with it.

If it's an sql timeout error, you will have to change the timeout value in your connection string
Aug 3 '07 #8
MGM
19
I converted it to an vb.net app and running it right now. A few times during the running I did get a timeout error for this line:

Expand|Select|Wrap|Line Numbers
  1. connSQL2.Open()
  2. Dim sqlComm2 = New SqlCommand("UPDATE phasedetails SET " & title & "='" & newDevphasing1 & "', " & title2 & "='" & newDevorien1 & "' WHERE ID=" & id, connSQL2)
  3. sqlComm2.ExecuteNonQuery()
  4. connSQL2.Close()
Specifically, the line sqlComm2.ExecuteNonQuery() is what's giving me the timeout error. Any reasons why? I fixed it (for now) by changing this line earlier in the code:

Expand|Select|Wrap|Line Numbers
  1. Dim sqlQuery = New String("SELECT TOP 1000 * FROM phasedetails WHERE " & title & "='" & UCase(oldDevphasing1) & "' OR " & title & "='" & LCase(oldDevphasing1) & "'")
To this line:

Expand|Select|Wrap|Line Numbers
  1. Dim sqlQuery = New String("SELECT TOP 1000 id,devphasing1,devphasing2,devphasing3,devorien1,devorien2,devorien3,condphasing1,condphasing2,condphasing3,condorien1,condorien2,condorien3 FROM phasedetails WHERE " & title & "='" & UCase(oldDevphasing1) & "' OR " & title & "='" & LCase(oldDevphasing1) & "'")
However, I have no idea if the timeout error will occur again over the weekend as this is running. Is there something else I should change to prevent this error from occuring?

MGM out
Aug 3 '07 #9
Plater
7,872 Expert 4TB
However, I have no idea if the timeout error will occur again over the weekend as this is running. Is there something else I should change to prevent this error from occuring?
There should be a timeout property you can set in your connection string.
(I know msSQL has one)
http://www.connectionstrings.com/
Aug 3 '07 #10
MGM
19
I looked at that page's SQL Server strings and didn't find anything on timeouts...

MGM out
Aug 3 '07 #11
Plater
7,872 Expert 4TB
Hmm I guess it's only a timeout for connecting.
You might have to go run through the SQL server itself's properties for a timeout then.
Aug 6 '07 #12
MGM
19
It's fine. I haven't gotten any timeout errors since last time. I got an exception error of some sort while running this over the weekend however, so I STILL haven't gotten this thing running. I figured it out and fixed it, and as of right now everything is running properly. I'm going to be checking this throughout the day to make sure it stays running properly. If so, I'll leave it running over night and hopefully it'll be done by tomorrow.

Thanks for the help everyone!

MGM out
Aug 6 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
16
by: mamo74 | last post by:
Hello. I am administering a SQL Server (Enterprise Edition on Windows 2003) from some month and can't understand what is going on in the latest week (when the db grow a lot). The DB is around...
15
by: Rolan | last post by:
There must be a way to enhance the performance of a query, or find a plausible workaround, but I seem to be hitting a wall. I have tried a few tweaks, however, there has been no improvement. ...
12
by: VMI | last post by:
For some reason, the process of retrieving data (about 20 records) from an Access table that has 400K records to a dataTable is taking over 3 mins. to complete. Below is my code to connect to the...
0
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
3
by: Geoff Jones | last post by:
Hi All I hope you'll forgive me for posting this here (I've also posted to ado site but with no response so far) as I'm urgently after a solution. Can anybody help me? I'm updating a table on...
13
by: Arno R | last post by:
Hi all, I am deploying an A2k app to users with different versions of Access. Using Access 2000 the relinking on startup (on deploying a new frontend or when backend has changed) is very fast....
5
by: coldpizza | last post by:
I am trying to fill a sqlite3 database with records, and to this end I have written a class that creates the db, the table and adds rows to the table. The problem is that the updating process is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.