Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 20 of 27 total
Thread Attempted to read or write protected memory. This is often an indication that ot
Mon, Feb 25 2008 2:53 AMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

Hi Hiba,

Yes that is correct

Chris Holland

Hiba Hable wrote:
> Hello,
> Do you that all what i need to write is the following:
>
> Using adp As New OdbcDataAdapter(datasql, Constants.odbccon)
>             adp.Fill(dtble)
> End Using
>
> and it should works, meaning that the dataadpater will be disposed after the endusing statment?
> Thank you
> Hiba
>
Thu, Feb 28 2008 2:21 AMPermanent Link

Hiba Hable
Hello,
I did as u told me and I used the using statment on every command and adapter and I am still getting this error randomly. is there anither reason for that error because i am stuck and i
dont know why i am encountering that error.
this error is exactly encountered when i have a function that loops over a datatable to change some data in that datatable accordingly. those changes are done by calling another functions
where i am getting that error, that function only excutes an sql and fill a datatable and return a value from that datatable. so i dont see why i am getting that error.
hope u can help.
thank u
Hiba
Thu, Feb 28 2008 3:21 AMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

Hi Hiba,

Can you post the code that you are using as an example?

Chris Holland

Hiba Hable wrote:
> Hello,
> I did as u told me and I used the using statment on every command and adapter and I am still getting this error randomly. is there anither reason for that error because i am stuck and i
> dont know why i am encountering that error.
> this error is exactly encountered when i have a function that loops over a datatable to change some data in that datatable accordingly. those changes are done by calling another functions
> where i am getting that error, that function only excutes an sql and fill a datatable and return a value from that datatable. so i dont see why i am getting that error.
> hope u can help.
> thank u
> Hiba
>
Thu, Feb 28 2008 3:41 AMPermanent Link

Hiba Hable
***Main function that is called in importreports class***************************
Public Function TSByPolImportfunc(ByVal repserial As String, ByVal repinput As ArrayList) As Boolean
       Dim result As Boolean = True
       Dim dcount As Integer = 0
       Dim dtble As New DataTable()
       Dim ptble As New DataTable()
       Dim recapdata As New DataSet

       'set the header of the dtble
       Dim dinput As New ArrayList
       dinput.Add("E\F")
       dinput.Add("CTR")
       dinput.Add("Seal")
       dinput.Add("Size")
       dinput.Add("Weight")
       dinput.Add("POL")
       dinput.Add("POD")

       'set the header of the recap
       Dim rinput As New ArrayList
       rinput.Add("POD")
       rinput.Add("TTL 20F")
       rinput.Add("TTL 40F")
       rinput.Add("TTL 20E")
       rinput.Add("TTL 40E")
       rinput.Add("TTL Weight KGS")


       Dim datasql As String = "select item.multiplecgo,item.seal,bill.bill,item.fullempty,item.cnr,item.tare,bill.pod,bill.pol,bill.tsport,bill.tsport2,bill.tsport3,bill.tsport4,item.gross,case when
cty.Teus = 1 then (cty.msct + 'X20') else (cty.msct +'X40') end as Type from Item join cty on Item.cty=cty.code join bill on (bill.bill = item.bill and bill.vessel=item.vessel and
bill.voyage=item.voyage) where (ttare = 0 Or ttare Is null) and bill.impexp = 'I' and item.secondcargo=0 and bill.pod <> 'LBBEY' and bill.vessel='" + repinput(22) + "' and bill.voyage='" +
repinput(1) + "'" + "order by bill.pol,item.fullempty desc,type,item.cnr"
       Using adp As New OdbcDataAdapter(datasql, Constants.odbccon)
           adp.Fill(dtble)
       End Using
       dcount = dtble.Rows.Count

       If dcount > 0 Then
           'set modifications on POL, seal, pod and pol name (disload = false =? discharge)
           ptble = com.setByPOLMod(dtble, repinput(22), repinput(1), "pol", "I", False) // on this function i get the error

           'get distinct pod
           Dim podtble As New DataTable
           podtble = com.sorttble(ptble, "pod")

           'recap
           Dim recaptble As New DataTable
           recaptble = com.PODSizeEF(podtble, ptble)
           recapdata.Tables.Add(recaptble)

           'creates instance of the reports class
           result = repobj.createReport(repserial, repinput, ptble, "", dinput, recapdata, "", rinput)
       End If
       Return result
   End Function
*****setbypolmod in commonfunctions class*********************************************************************************************************
Public Function setByPOLMod(ByVal dtble As DataTable, ByVal vsl As String, ByVal voy As String, ByVal str As String, ByVal impexp As String, ByVal disload As Boolean) As DataTable
       ' create columns of the ptable
       Dim ptble As New DataTable
       Dim efcol As New DataColumn("ef", System.Type.GetType("System.String"))
       ptble.Columns.Add(efcol)
       Dim ctrcol As New DataColumn("ctr", System.Type.GetType("System.String"))
       ptble.Columns.Add(ctrcol)
       Dim sealcol As New DataColumn("seal", System.Type.GetType("System.String"))
       ptble.Columns.Add(sealcol)
       Dim sizecol As New DataColumn("size", System.Type.GetType("System.String"))
       ptble.Columns.Add(sizecol)
       Dim weightcol As New DataColumn("weight", System.Type.GetType("System.String"))
       ptble.Columns.Add(weightcol)

       If str = "pol" Then
           Dim polcol As New DataColumn("pol", System.Type.GetType("System.String"))
           ptble.Columns.Add(polcol)
       End If

       Dim podcol As New DataColumn("pod", System.Type.GetType("System.String"))
       ptble.Columns.Add(podcol)


       Dim drow As DataRow
       For i As Integer = 0 To dtble.Rows.Count - 1
           drow = dtble.Rows(i)
           'pol
           If str = "pol" Then
               drow.Item("pol") = setPOL(drow)
               drow.Item("pol") = stat.getPortName(drow.Item("pol")) // on this function i get the error
           End If
           'seal
           drow.Item("seal") = getAllSeals(drow.Item("bill"), vsl, voy, drow.Item("cnr"), drow.Item("seal")) // on this function i get the error
           'pod
           drow.Item("pod") = stat.getPortName(drow.Item("pod")) // on this function i get the error
           'weight
           If drow.Item("multiplecgo") = True Then
               drow.Item("gross") = FormatNumber(drow.Item("gross") + getmultipleweight(drow.Item("bill"), vsl, voy, drow.Item("cnr"), impexp, drow.Item("tare"), disload), 2,
TriState.False) // on this function i get the error

           Else
               drow.Item("gross") = FormatNumber(getTotalWeight(drow), 2, TriState.False)
           End If
       Next

       dtble.DefaultView.Sort = str
       Dim j As Integer = 0

       'loop over dataview and replace pol
       For Each row As DataRowView In dtble.DefaultView
           Dim prow As DataRow
           prow = ptble.NewRow()
           prow.Item("ef") = row.Item("fullempty")
           prow.Item("ctr") = row.Item("cnr")
           prow.Item("seal") = row.Item("seal")
           prow.Item("size") = row.Item("type")
           prow.Item("weight") = row.Item("gross")
           If str = "pol" Then prow.Item("pol") = row.Item("pol")
           prow.Item("pod") = row.Item("pod")
           ptble.Rows.Add(prow)
       Next row
       Return ptble
   End Function
************getportname in staticfunction class*************************************************************************************************
Public Function getPortName(ByVal pcode As String) As String
       Dim port As String = ""
       Dim datasql As String = "select description from isoloc where code='" + pcode + "'"
       Using myCommand As New OdbcCommand(datasql, Constants.odbccon)
           port = myCommand.ExecuteScalar()
       End Using
       If port Is System.DBNull.Value Then port = " "
       Return port
   End Function
***********getallseals function in commonfunctions class******************************************************************************************************
Public Function getAllSeals(ByVal bl As String, ByVal vsl As String, ByVal voy As String, ByVal cnr As String, ByVal seal1 As String) As String
       Dim seal As String = seal1
       Dim dtble As New DataTable
       Dim datasql As String = "select seal from itemsSeals where bill='" + bl + "' and vessel='" + vsl + "' and voyage='" + voy + "' and cnr='" + cnr + "'"
       Using adp As New OdbcDataAdapter(datasql, Constants.odbccon)
           adp.Fill(dtble)
       End Using
       If dtble.Rows.Count > 0 Then
           For i As Integer = 0 To dtble.Rows.Count - 1
               seal = seal + " - " + dtble.Rows(i).Item("seal")
           Next
       End If
       Return CStr(seal)
   End Function
*****getmultipleweight function in commonfunctions*********************************************
'get multiple cargo weight + tare
   Private Function getmultipleweight(ByVal bl As String, ByVal vsl As String, ByVal voy As String, ByVal cnr As String, ByVal impexp As String, ByVal tare As Integer, ByVal disload As
Boolean) As Double
       'get weight of all second cargo
       Dim weight As Double = 0
       Dim dtble As New DataTable

       Dim loaddisstr As String = ""
       If disload = True Then 'loading
           loaddisstr = " and bill.pod <> 'LBBEY'"
       Else 'discharge
           loaddisstr = " and bill.sort='True'"
       End If

       Dim datasql As String = "select item.cnr,item.gross as weight from item join bill on (bill.bill=item.bill and bill.vessel=item.vessel and bill.voyage=item.voyage) where item.cnr='" + cnr
+ "' and bill.bill = '" + bl + "' and bill.vessel='" + vsl + "' and bill.voyage='" + voy + "' and item.secondcargo=1 and bill.impexp='" + impexp + "' " + loaddisstr
       Using adp As New OdbcDataAdapter(datasql, Constants.odbccon)
           adp.Fill(dtble)
       End Using
       If dtble.Rows.Count > 0 Then
           For i As Integer = 0 To dtble.Rows.Count - 1
               weight = weight + dtble.Rows(i).Item("weight")
           Next
           weight = weight + tare
       End If
       Return weight
   End Function
****************************************************************************************************************************************************

I am getting the error on either   port = myCommand.ExecuteScalar() of getportname function or  adp.Fill(dtble) of getallseals function or  adp.Fill(dtble) of getmultipleweight function.
Thanx
Hiba
Thu, Feb 28 2008 6:48 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Hiba,

<<  I am getting the error on either   port = myCommand.ExecuteScalar() of
getportname function or  adp.Fill(dtble) of getallseals function or
adp.Fill(dtble) of getmultipleweight function. >>

How/where is the connection object being created ?  Are any of the ODBC*
objects being created as static class
variables ?

DBISAM requires that you keep connections and their associated objects
separate for each thread, so if any objects are being shared among multiple
threads, then you're going to have problems.

--
Tim Young
Elevate Software
www.elevatesoft.com

Thu, Feb 28 2008 7:40 AMPermanent Link

Hiba Hable
How/where is the connection object being created ?  Are any of the ODBC*
objects being created as static class
variables ?

DBISAM requires that you keep connections and their associated objects
separate for each thread, so if any objects are being shared among multiple
threads, then you're going to have problems.

Hello,
The connection object is being created on the login form of the main application meaning that when the user is authenticated i open the connecyions to both odbc and sql server as follows:
Constants.con.Open()
Constants.odbccon.Open()
and i am saving the "con" and "odbccon" variables in a constants class that are declared as follows:
'sql connection
 Public Shared con As New SqlConnection("Data Source=sql2005;Initial Catalog=QQuest;Integrated Security=True")
'odbc connection
 Public Shared odbccon As New OdbcConnection("dsn=MSCA")   

So this is what u mean? if this is the problem then how can i solve it? menaing where shall i open the connecyions?
thx
Hiba
Fri, Feb 29 2008 8:16 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Hiba,

<< The connection object is being created on the login form of the main
application meaning that when the user is authenticated i open the
connecyions to both odbc and sql server as follows: >>

Okay, that should be okay as long as the application isn't multi-threaded.
Did you check out the link that Frans Dalen posted here ?

http://www.elevatesoft.com/scripts/newsgrp.dll?action=openmsg&group=14&msg=1623&page=1

Does that situation apply to any of your tables ?

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, Mar 3 2008 8:30 AMPermanent Link

Hiba Hable
Hello,
I have 2 applications using the dbisam tables, one implemented using delphi (developed by the head office) and the other complemetary application developed by Vb.net. so i have to check
with the head office concerning the indexes on the dbisam tables. what if the other application cant work w/o the indexes than i am stuck! so is there other driver where i can connect to the
dbisam tables where it ignores the indexes? or is there other solution?
Thank you
Hiba
Mon, Mar 3 2008 9:59 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Hiba,

<< I have 2 applications using the dbisam tables, one implemented using
delphi (developed by the head office) and the other complemetary application
developed by Vb.net. so i have to check with the head office concerning the
indexes on the dbisam tables. what if the other application cant work w/o
the indexes than i am stuck! so is there other driver where i can connect to
the dbisam tables where it ignores the indexes? or is there other solution?
>>

Just to clarify - I haven't actually reproduced this issue in all cases, but
I do know that it can be an issue if the calling application does not
respect the way that the RecordID column information is returned via the
ODBC catalog functions.  I believe that the MS Office applications like
Access have an issue with this, but I haven't been able to get Visual Studio
to have an issue with this in the Server Explorer, so it may not be an issue
with VB.NET.

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Mar 4 2008 8:40 AMPermanent Link

Hiba Hable
Hello,
The subjected tables that are causing the error has no index on them as confirmed by the head office. so how this problem can be solved ? any other alternatives?
and plz can you clarify what u mean by ur last reply?
thank you in advance
Hiba
« Previous PagePage 2 of 3Next Page »
Jump to Page:  1 2 3
Image