943,831 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1243
  • VB.NET RSS
May 4th, 2008
0

Program loses response during large DB queries VB.NET

Expand Post »
Hi,
When I execute queries which have a lot of data returned in the recordset my VB app seems to hang (IE: This program is not responding)

I'm using ODBC to connect to the database and am using Postgres DB

VB.NET Syntax (Toggle Plain Text)
  1. Public db_name As String
  2. Public db_username As String
  3. Public db_userpassword As String
  4. Public db_server As String
  5.  
  6. Public connStr As String
  7. Public sqlCommand As OdbcCommand
  8. Public sqlConn As OdbcConnection
  9. Public Rs As OdbcDataReader
  10.  
  11. Public Sub DoQuery(ByVal tmpSQL as String)
  12. connStr = "Driver={PostgreSQL ANSI};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword
  13.  
  14. sqlCommand = New OdbcCommand
  15. sqlConn = New OdbcConnection(connStr)
  16. If sqlConn.State = ConnectionState.Closed Then
  17. sqlConn.Open()
  18. End If
  19.  
  20. sqlCommand.CommandType = CommandType.Text
  21. sqlCommand.Connection = sqlConn
  22. sqlCommand.CommandText = tmpSQL
  23.  
  24. Rs = sqlCommand.ExecuteReader
  25.  
  26. End Sub

I'm not sure that there is a way to sort this out, I hope there is?

Thanks all!
Reputation Points: 10
Solved Threads: 2
Newbie Poster
danielgee is offline Offline
15 posts
since May 2008
May 6th, 2008
0

Re: Program loses response during large DB queries VB.NET

I would try to limit the amount of data for each query.
Using the reader in order to populate some kind of repository do take a long time.
The way the reader works is that it only reads one line of data at a time.
Ie:
VB.NET Syntax (Toggle Plain Text)
  1. While Rs.Read
  2. If Not IsDBNull(Rs.Item("some_column_name")) Then repository = Rs.Item("some_column_name")
  3. End While
However, if you limit the amount of data to read with a WHERE clause this will go faster.

Or, you could use a dataadapter/dataset and basically get a mirror copy of the data.
Then you can search and select from there.
VB.NET Syntax (Toggle Plain Text)
  1. Public db_name As String
  2. Public db_username As String
  3. Public db_userpassword As String
  4. Public db_server As String
  5.  
  6. Public connStr As String
  7. Public sqlCommand As OdbcCommand
  8. Public sqlConn As OdbcConnection
  9. Public Rs As OdbcDataReader '''Remove this
  10. Public Da as OdbcDataAdapter '''Replace with this
  11. Public sqlComBuilder as OdbcCommandBuilder '''Add this
  12. Public Ds As DataSet '''Add this too
  13.  
  14. Public Sub DoQuery(ByVal tmpSQL as String)
  15. connStr = "Driver={PostgreSQL ANSI};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword
  16.  
  17. sqlConn = New OdbcConnection(connStr)
  18. Da = New OdbcDataAdapter(tmpSQL, sqlConn)
  19. sqlComBuilder = New OdbcCommandBuilder(Da)
  20. Ds = New DataSet()
  21.  
  22. sqlConn.Open()
  23. Da.Fill(Ds,"name_of_table")
  24. sqlConn.Close()
  25. End Sub
The CommandBuilder is used to automatically create INSERT/DELETE/UPDATE queries when you need to update, insert or delete information in the database. Good thing to use if you don't want to create long and complicated queries manually.
Reputation Points: 87
Solved Threads: 128
Practically a Master Poster
Oxiegen is offline Offline
652 posts
since Jun 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Converting from C# .NET 1.0 to VB.NET 2.0
Next Thread in VB.NET Forum Timeline: Disable user to change tab





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC