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

Memory use and retention

Hi,

I have an app that is interfacing with a large SQL dbase. I have generated a
database class to house all of the Data adapter and SQL commands, I have
posted example code below.

I can now call the required table by using . . .

db.CVI.fill(dt, criteria)

Or use the Table function like . .

db.CVI.table(CurrentContract.id)

Although this works very well, I am now seeing issues with memory use and
retention. I have tested my app for 15mins visiting most screens and have
seen memory use (VM) of 65 - 75 MB.

I understood that variables and objects are disposed of when they go out of
scope, and are then picked up by the garbage collector, but will this also
apply for any objects I create from my db class ? I seem to be keeping hold
of these datatables for the remainder or the session, until the user closes
the app.

Any pointers on this much appreciated !

Cheers
Bob

Example db class . . .

[VBCODE]
Class db
Class CVI
Private Shared mda As SqlDataAdapter

Friend Shared Function table(ByVal Contract As String) As DataTable
Dim dt As New DataTable("CVI")
Fill(dt, CurrentContract.ID) '***
Return dt '***
End Function

Friend Shared Function NextCVI(ByVal Contract As String) As Integer
Dim cmd As New SqlCommand("SELECT Max(Number) FROM CVI WHERE
Contract='" & Contract & "'", cnn)
Dim bOpen As Boolean = cnn.State = ConnectionState.Open
Try
If Not bOpen Then cnn.Open()
Dim nRtn As Object = cmd.ExecuteScalar
If IsNumeric(nRtn) Then
Return CInt(nRtn) + 1
Else
Return 1
End If
Finally
If Not bOpen Then cnn.Close()
End Try
End Function

Friend Shared Function Fill(ByVal dt As DataTable, ByVal Contract As
String) As Integer
DataAdapter.SelectCommand.Parameters(0).Value = Contract
Return DataAdapter.Fill(dt)
End Function

Friend Shared Function Update(ByVal dt As DataTable) As Integer
Return DataAdapter.Update(dt)
End Function

Private Shared Function DataAdapter() As SqlDataAdapter
If Not mda Is Nothing Then Return mda
mda = New SqlDataAdapter
With mda
.DeleteCommand = New SqlCommand
.InsertCommand = New SqlCommand
.UpdateCommand = New SqlCommand
.SelectCommand = New SqlCommand
With .SelectCommand
.Connection = cnn
.CommandText = "SELECT * FROM vw_CVI where Contract =
@Contract"
.Parameters.Add("@contract", SqlDbType.VarChar, 8)

End With
With .DeleteCommand
.Connection = cnn
.CommandText = "DELETE FROM CVI WHERE =@"
.Parameters.Add("@", SqlDbType.Int, 0, "")
End With
With .InsertCommand
.Connection = cnn
.CommandText = "INSERT INTO CVI" & _
" ( Contract, Number, IssuedToContact, Subject,
DateIssued, Detail, Staff, InstructionIssuedBy, InstructionIssuedTo, & _
InstructionIssuedDate ,CrossReference )" & _
"VALUES (@Contract, @Number, @IssuedToContact, @Subject,
@DateIssued, @Detail, @Staff, @InstructionIssuedBy, & _
@InstructionIssuedTo, @InstructionIssuedDate,@CrossReference )"
.Parameters.Add("@Contract", SqlDbType.VarChar, 8,
"Contract")
.Parameters.Add("@Number", SqlDbType.Int, 4, "Number")
.Parameters.Add("@IssuedToContact", SqlDbType.VarChar,
30, "IssuedToContact")
.Parameters.Add("@Subject", SqlDbType.VarChar, 30,
"Subject")
.Parameters.Add("@DateIssued", SqlDbType.DateTime, 8,
"DateIssued")
.Parameters.Add("@Detail", SqlDbType.VarChar, 0, "Detail")
.Parameters.Add("@Staff", SqlDbType.Int, 4, "Staff")
.Parameters.Add("@InstructionIssuedBy",
SqlDbType.VarChar, 30, "InstructionIssuedBy")
.Parameters.Add("@InstructionIssuedTo", SqlDbType.Int,
4, "InstructionIssuedTo")
.Parameters.Add("@InstructionIssuedDate",
SqlDbType.DateTime, 8, "InstructionIssuedDate")
.Parameters.Add("@CrossReference", SqlDbType.VarChar, 0,
"CrossReference")
End With
With .UpdateCommand
.Connection = cnn
.CommandText = "UPDATE CVI " & _
"SET Contract=@Contract, Number=@Number,
IssuedToContact=@IssuedToContact, Subject=@Subject, DateIssued=@DateIssued, &
_
Detail=@Detail, Staff=@Staff, InstructionIssuedBy=@InstructionIssuedBy,
InstructionIssuedTo=@InstructionIssuedTo, & _
InstructionIssuedDate=@InstructionIssuedDate, CrossReference=@CrossReference
" & _
"WHERE id=@id"
.Parameters.Add("@Contract", SqlDbType.VarChar, 8,
"Contract")
.Parameters.Add("@Number", SqlDbType.Int, 4, "Number")
.Parameters.Add("@IssuedToContact", SqlDbType.VarChar,
30, "IssuedToContact")
.Parameters.Add("@Subject", SqlDbType.VarChar, 30,
"Subject")
.Parameters.Add("@DateIssued", SqlDbType.DateTime, 8,
"DateIssued")
.Parameters.Add("@Detail", SqlDbType.VarChar, 0, "Detail")
.Parameters.Add("@Staff", SqlDbType.Int, 4, "Staff")
.Parameters.Add("@InstructionIssuedBy",
SqlDbType.VarChar, 30, "InstructionIssuedBy")
.Parameters.Add("@InstructionIssuedTo", SqlDbType.Int,
4, "InstructionIssuedTo")
.Parameters.Add("@InstructionIssuedDate",
SqlDbType.DateTime, 8, "InstructionIssuedDate")
.Parameters.Add("@CrossReference", SqlDbType.VarChar, 0,
"CrossReference")
.Parameters.Add("@", SqlDbType.Int, 0, "")
End With
AddHandler .FillError, AddressOf Fill_Error
AddHandler .RowUpdated, New
SqlRowUpdatedEventHandler(AddressOf DataAdapter_OnRowUpdated)
End With
Return mda
End Function
Private Shared Sub Fill_Error(ByVal sender As Object, ByVal e As
FillErrorEventArgs)
If TypeOf e.Errors Is Data.ConstraintException Then e.Continue =
True
End Sub
Private Shared Sub DataAdapter_OnRowUpdated(ByVal sender As Object,
ByVal args As SqlRowUpdatedEventArgs)
Dim newID As Integer = 0
Dim idCMD As SqlCommand = New SqlCommand("SELECT @@IDENTITY",
DataAdapter.UpdateCommand.Connection)
If args.StatementType = StatementType.Insert Then
Try
newID = CInt(idCMD.ExecuteScalar())
Catch ex As Exception
EH.Log(ex, EH.eErrorLogging.DisplayAndFile)
End Try

args.Row("ID") = newID
End If
End Sub
End Class

'repeats for 43 other tables !

end class
[/VBCODE]
Nov 21 '05 #1
0 914

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

Similar topics

0
by: Peter Rennie | last post by:
The System.Diagnostics.EventLog class allows you to create custom event logs. The logs are created with a default size of 512KB and 7 days retention. Does anyone know of a way to change these...
0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
15
by: Alexis | last post by:
Hello, I'm working on a project that uses over a hundred XLSs for transforming xml documents. The project consists of several webservices (IIS) calling a few dlls. This dlls make the business...
22
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
4
by: xixi | last post by:
i have a very serious memory problem, we have db2 udb v8.1 load on a HP titanium machine with 4 G memory, it is 64bit machine, currently on DB2 instance , i have three databases, but only one is...
3
by: www.dir | last post by:
I am developing C# application that every 10 seconds refreshes TreeView control. I am using 3 custom classes for renewing the TreeView control. And It seems that I do not free some resources, so...
1
by: nevsoft | last post by:
Hello I have Oracle 10.2.0.1 on Solaris 10g. I want to make level0 incremental backup every night and level1 incremental backup during the day. Each level0 backup will be copied over network...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...

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.