473,396 Members | 1,693 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,396 software developers and data experts.

NOVICE: SQL Query on a Timer, Growing Memory Size

hello, thanks for reading.

this topic was probably covered in the past; if so, i apologize for
the repost, and would you kindly redirect me to the topic?

i have small app that monitors the state of a database. this is
achieved by a sql query running in timed increments, tied to the
"tick" event handler of the Timer control. basically, a sql query is
run every five seconds to get a count of items in a table.

the code used:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Dim conn3 As New System.Data.SqlClient.SqlConnection(******)
Dim sqlString3 As String = "select count(recipient) from
board"
Dim adapter3 As New SqlDataAdapter(sqlString3, conn3)
Dim ds3 As New Data.DataSet

adapter3.Fill(ds3)

createTextIcon(CInt(ds3.Tables(0).Rows(0).Item(0))

adapter3.Dispose()
ds3.Clear()

End Sub

this achieves the desired result, but i noticed the memory usage
increases by about 12kb at each iteration. i imagine this is due to
the dataset [ds3] being filled. i thought that clearing the dataset
[ds3.clear()] would alleviate this issue, but it doesn't.

am i even going about this the right way? someone mentioned caching
the query. does anyone have any suggestions?

any help would be greatly appreciated.

-Joe.
Jan 8 '08 #1
5 1584
Joe,

You might consider using an SQLCommand object's ExecuteScalar method to
return the count, without using a dataadapter or a dataset.

Kerry Moorman
"Joe C." wrote:
hello, thanks for reading.

this topic was probably covered in the past; if so, i apologize for
the repost, and would you kindly redirect me to the topic?

i have small app that monitors the state of a database. this is
achieved by a sql query running in timed increments, tied to the
"tick" event handler of the Timer control. basically, a sql query is
run every five seconds to get a count of items in a table.

the code used:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Dim conn3 As New System.Data.SqlClient.SqlConnection(******)
Dim sqlString3 As String = "select count(recipient) from
board"
Dim adapter3 As New SqlDataAdapter(sqlString3, conn3)
Dim ds3 As New Data.DataSet

adapter3.Fill(ds3)

createTextIcon(CInt(ds3.Tables(0).Rows(0).Item(0))

adapter3.Dispose()
ds3.Clear()

End Sub

this achieves the desired result, but i noticed the memory usage
increases by about 12kb at each iteration. i imagine this is due to
the dataset [ds3] being filled. i thought that clearing the dataset
[ds3.clear()] would alleviate this issue, but it doesn't.

am i even going about this the right way? someone mentioned caching
the query. does anyone have any suggestions?

any help would be greatly appreciated.

-Joe.
Jan 8 '08 #2
"Joe C." <js******@gmail.comwrote in news:1c9c5e00-4263-46f8-9f62-
6a**********@d70g2000hsb.googlegroups.com:
the code used:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Dim conn3 As New System.Data.SqlClient.SqlConnection(******)
Dim sqlString3 As String = "select count(recipient) from
board"
Dim adapter3 As New SqlDataAdapter(sqlString3, conn3)
Dim ds3 As New Data.DataSet

adapter3.Fill(ds3)

createTextIcon(CInt(ds3.Tables(0).Rows(0).Item(0))

adapter3.Dispose()
ds3.Clear()

End Sub
You should use a SQLCommand object and use the "ExecuteScalar" function
to return a single value. More efficient than what you're doing.
this achieves the desired result, but i noticed the memory usage
increases by about 12kb at each iteration. i imagine this is due to
the dataset [ds3] being filled. i thought that clearing the dataset
[ds3.clear()] would alleviate this issue, but it doesn't.
Memory will keep growing until the garbage collector kicks in. How much
memory is it using it? If you let it run for a while, I'm sure memory
will stablize.

--
sp**********@rogers.com (Do not e-mail)
Jan 8 '08 #3
you're absolutely right, it occupies about 4 megs to start, then
stablizes at 7.5 megs or so.

i'll give the sqlcommand a go.

thank you very much! i sincerely do appreciate the help, i'll let you
know how it turns out.

On Jan 8, 1:38*pm, Spam Catcher <spamhoney...@rogers.comwrote:
"Joe C." <jsk.c...@gmail.comwrote in news:1c9c5e00-4263-46f8-9f62-
6ac9c6a8f...@d70g2000hsb.googlegroups.com:


the code used:
* * Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
* * * * Dim conn3 As New System.Data.SqlClient.SqlConnection(******)
* * * * Dim sqlString3 As String = "select count(recipient) from
board"
* * * * Dim adapter3 As New SqlDataAdapter(sqlString3, conn3)
* * * * Dim ds3 As New Data.DataSet
* * * * adapter3.Fill(ds3)
* * * * createTextIcon(CInt(ds3.Tables(0).Rows(0).Item(0))
* * * * adapter3.Dispose()
* * * * ds3.Clear()
* * End Sub

You should use a SQLCommand object and use the "ExecuteScalar" function
to return a single value. More efficient than what you're doing.
this achieves the desired result, but i noticed the memory usage
increases by about 12kb at each iteration. *i imagine this is due to
the dataset [ds3] being filled. *i thought that clearing the dataset
[ds3.clear()] would alleviate this issue, but it doesn't.

Memory will keep growing until the garbage collector kicks in. How much
memory is it using it? If you let it run for a while, I'm sure memory
will stablize.

--
spamhoney...@rogers.com (Do not e-mail)- Hide quoted text -

- Show quoted text -
Jan 8 '08 #4
Generally, you should use a "Using" block with any object that has a
".Dispose" method. e.g. for your code:

Using conn3 As New System.Data.SqlClient.SqlConnection
Dim sqlString3 As String = "select count(recipient) from board"
Using adapter3 As New SqlDataAdapter(sqlString3, conn3)
Using ds3 As New Data.DataSet
adapter3.Fill(ds3)
createTextIcon(CInt(ds3.Tables(0).Rows(0).Item(0))
ds3.Clear()
End Using
End Using
End Using

This will help the garbage collector clean them up more quickly.

If you want to keep the objects around (e.g. for performance reasons) then
declare them at the module level, and .Dispose them in the Form.FormClosed
event.

--
David Streeter
Synchrotech Software
Sydney Australia
"Joe C." wrote:
hello, thanks for reading.

this topic was probably covered in the past; if so, i apologize for
the repost, and would you kindly redirect me to the topic?

i have small app that monitors the state of a database. this is
achieved by a sql query running in timed increments, tied to the
"tick" event handler of the Timer control. basically, a sql query is
run every five seconds to get a count of items in a table.

the code used:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Dim conn3 As New System.Data.SqlClient.SqlConnection(******)
Dim sqlString3 As String = "select count(recipient) from
board"
Dim adapter3 As New SqlDataAdapter(sqlString3, conn3)
Dim ds3 As New Data.DataSet

adapter3.Fill(ds3)

createTextIcon(CInt(ds3.Tables(0).Rows(0).Item(0))

adapter3.Dispose()
ds3.Clear()

End Sub

this achieves the desired result, but i noticed the memory usage
increases by about 12kb at each iteration. i imagine this is due to
the dataset [ds3] being filled. i thought that clearing the dataset
[ds3.clear()] would alleviate this issue, but it doesn't.

am i even going about this the right way? someone mentioned caching
the query. does anyone have any suggestions?

any help would be greatly appreciated.

-Joe.
Jan 8 '08 #5
thank you for the great advice, i've gone ahead and fixed the code as
such:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Dim conn3 As New SqlConnection(******)
Dim sqlStr As String = "select count(recipient) from board"
Dim sqlComm As New SqlCommand(sqlStr, conn3)

conn3.Open()
nuTic = CInt(sqlComm.ExecuteScalar())
conn3.Close()
conn3.Dispose()

createTextIcon(nuTic)

End Sub

the above is yielding the exact same results as before, and i do
totally prefer how lean it is.

however, the memory allocation is still growing, albeit at a smaller
increment (roughly 4kb). having monitored the process through the
task manager, i noticed that once it reaches a certain size, it drops
down, then back up, just seesawing back and forth.

so, as a conclusion, i think the app, as it is, should be ok to
deploy.

thank you for all your help!

- Joe.

On Jan 8, 1:38*pm, Spam Catcher <spamhoney...@rogers.comwrote:
"Joe C." <jsk.c...@gmail.comwrote in news:1c9c5e00-4263-46f8-9f62-
6ac9c6a8f...@d70g2000hsb.googlegroups.com:


the code used:
* * Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
* * * * Dim conn3 As New System.Data.SqlClient.SqlConnection(******)
* * * * Dim sqlString3 As String = "select count(recipient) from
board"
* * * * Dim adapter3 As New SqlDataAdapter(sqlString3, conn3)
* * * * Dim ds3 As New Data.DataSet
* * * * adapter3.Fill(ds3)
* * * * createTextIcon(CInt(ds3.Tables(0).Rows(0).Item(0))
* * * * adapter3.Dispose()
* * * * ds3.Clear()
* * End Sub

You should use a SQLCommand object and use the "ExecuteScalar" function
to return a single value. More efficient than what you're doing.
this achieves the desired result, but i noticed the memory usage
increases by about 12kb at each iteration. *i imagine this is due to
the dataset [ds3] being filled. *i thought that clearing the dataset
[ds3.clear()] would alleviate this issue, but it doesn't.

Memory will keep growing until the garbage collector kicks in. How much
memory is it using it? If you let it run for a while, I'm sure memory
will stablize.

--
spamhoney...@rogers.com (Do not e-mail)- Hide quoted text -

- Show quoted text -
Jan 9 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: bearophileHUGS | last post by:
Hello, I have four things to ask or to suggest, sorry if they seem basic or already discussed. ------------------- I am still ignorant about Tkinter. This little program, after pressing the...
14
by: Sonic | last post by:
I have an MDE file that is growing exponentially (from 3,900 KB to over 132,000 KB today). I am not saving data in this MDE, although I use a mix of offline and SQL tables for Read Only querying. ...
4
by: archana | last post by:
Hi all I am having application which is using server based timer that is timer from namespace system.timer. I am having windows service which i want to run after every 1 hour and after...
4
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts...
1
by: traceable1 | last post by:
I have 2 SQL databases which are the same and are giving me different query plans. select s.* from hlresults h inner join specimens s on s.specimen_tk = h.specimen_tk where s.site_tk = 9 and...
2
by: Navneet Kumar | last post by:
Hi, My program is non-leaky, I've checked on that. More virtual memory is allocated to it by the system then is required by it. I'm filling a linked list which grows in size to around 1GB (at this...
1
by: Vincent | last post by:
I do not have a strong grasp of the winsock library, but have started fiddling around with it a bit. My first impression is that using winsock in Access is a bit unwieldy. I was making a...
4
by: yashgt | last post by:
Hi, We have created a SQL server 2000 database. We observe that the transaction log keeps growing over time. We are now about to run out of space. We have been periodically shrinking the...
3
by: Javilen | last post by:
Hello, I am looking for some Query Optimization help, We are running a web application that is growing experientially in traffic and we are not running into Problems with Deadlocks on the SQL...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.