VB.NET 2005 - datatable.update

Last post 06-20-2012 7:45 PM by mickdoev. 18 replies.
Page 1 of 2 (19 items) 1 2 Next >
Sort Posts: Previous Next
  • 06-15-2012 11:36 PM

    VB.NET 2005 - datatable.update

    Environment = VB.NET 2005 & Pervasive SQL 9.5 ADO.NET

    Can someone please try to explain this behavour . . . .

    I have made a simple example to demonstrate the problem I am experiencing.

    I have single database table (customers) with the columns "cust_code" and "description"

    This table is presented in VB.NET 2005 as a single form datagrid (bindingsource/dataset).

    In this example, the database table is populated with the following data

    cust_code     description
    SHELL          Shell Oil
    BP                British Petrolium
    MOB             Mobile


    Here is the sequence of operations that produces the bizzar behaviour.

    In the editable datagrid;
    1. remove the row with PK = MOB -> save_button -> Database correctly updates
    2. add a new row with PK = KFC -> save_button -> Database correctly updates
    3. remove row with PK = SHELL -> save_button -> Database exception occurs

    On this last command, the row SHELL is INSERTED into the Database !!, not removed.

    Here is the code

    [CODE]Imports Pervasive.Data.SqlClient
    Public Class _test
        Dim connect_string As String = "Database Name=_testdb;Host=_testhost;Password=abc;Persist Security Info=True;User ID=basic"
        Dim psqlconnect As New PsqlConnection(connect_string)
        Dim customertableadapter As New PsqlDataAdapter("Select * from customers", psqlconnect)

        Private Sub customer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Get psql update insert and delete commands
            Call getpsqlcommands()

            'populate datagrid
            Try
                psqlconnect.Open()
                Me.customertableadapter.Fill(Me.ds_customers.customers)
                psqlconnect.Close()
            Catch ex As Exception
                psqlconnect.Close()
                MessageBox.Show("Error loading records :" & ex.ToString, "Problem", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        End Sub

        Private Sub save_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_btn.Click
            'save datagrid updates
            Dim rows_updated As Integer = 0
            Try
                Me.Validate()
                Me.CustomerBindingSource.EndEdit()
                psqlconnect.Open()
                rows_updated = Me.customertableadapter.Update(Me.ds_customers.customers)
                psqlconnect.Close()
                If rows_updated = 0 Then
                    Beep()
                    MessageBox.Show("No changes detected")
                Else
                    Beep()
                    MessageBox.Show("Updated " & rows_updated & " row(s)")
                End If
            Catch ex As Exception
                psqlconnect.Close()
                MessageBox.Show("Error updating records :" & ex.ToString, "Problem", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        End Sub

        Private Sub getpsqlcommands()
            'Define update commands
            Dim updatecmd As PsqlCommand
            Dim insertcmd As PsqlCommand
            Dim deletecmd As PsqlCommand
            Dim upparm As PsqlParameter
            Dim delparm As PsqlParameter

            updatecmd = New PsqlCommand("UPDATE customers SET description = ? WHERE cust_code = ?", psqlconnect)
            updatecmd.Parameters.Add("@description", PsqlDbType.VarChar, 50, "description")
            upparm = updatecmd.Parameters.Add("@cust_code", PsqlDbType.VarChar, 5, "cust_code")
            upparm.SourceVersion = DataRowVersion.Original
            customertableadapter.UpdateCommand = updatecmd

            insertcmd = New PsqlCommand("INSERT into customers (cust_code, description) VALUES(?,?)", psqlconnect)
            insertcmd.Parameters.Add("@cust_code", PsqlDbType.VarChar, 5, "cust_code")
            insertcmd.Parameters.Add("@description", PsqlDbType.VarChar, 50, "description")
            customertableadapter.InsertCommand = insertcmd

            deletecmd = New PsqlCommand("DELETE from customers WHERE cust_code = ?", psqlconnect)
            delparm = deletecmd.Parameters.Add("@cust_code", PsqlDbType.VarChar, 5, "cust_code")
            delparm.SourceVersion = DataRowVersion.Original
            customertableadapter.DeleteCommand = deletecmd
        End Sub[/CODE]

     

    If I modify the code to include a call to the "getsqlcommands" before each save (as below), it works correcly!

    Is it right that you need to "refresh" the sqlupdate commands before each update?


        Private Sub save_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_btn.Click
            'save datagrid updates
            Dim rows_updated As Integer = 0
            Try
                Me.Validate()
                Me.CustomerBindingSource.EndEdit()
               Call getpsqlcommands()                           ' adding this line fixes the problem ************
                psqlconnect.Open()
                rows_updated = Me.customertableadapter.Update(Me.ds_customers.customers)
                psqlconnect.Close()
                If rows_updated = 0 Then
                    Beep()
                    MessageBox.Show("No changes detected")
                Else
                    Beep()
                    MessageBox.Show("Updated " & rows_updated & " row(s)")
                End If
            Catch ex As Exception
                psqlconnect.Close()
                MessageBox.Show("Error updating records :" & ex.ToString, "Problem", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        End Sub

  • 06-16-2012 8:16 AM In reply to

    Re: VB.NET 2005 - datatable.update

     I've never seen anything like that before. What is the actual version of Pervasive.Data.SqlClient.DLL? I don't have v9.5 but can try to test in v11. 

    PSQl v9.5 is very old and isn't supported any more by Pervasive.  Since you've got a workaround, you should use that.  Otherwise, you should upgrade to PSQL v11 (currently supported product) and use the latest ADO.NET provider. If it still happens in v11, Pervasive will look at the problem.

  • 06-16-2012 6:43 PM In reply to

    Re: VB.NET 2005 - datatable.update

    Thanks for your reply. 

    The version of the Pervasive.Data.SqlClient.dll is 3.0.0.0

    I would really appreciate your efforts if you could test this for me with your version . 

     

  • 06-16-2012 8:26 PM In reply to

    Re: VB.NET 2005 - datatable.update

     I took your code, created a new project in VS 2010 (it's what I have).  THe project targets .NET 2.0.  I added the Pervasive ADO.NET provider 3.5.0.1820 reference.  I created a table and inserted data using the statements below:

    create table customers (cust_code char(10), description char(255));
    insert into customers values ('SHELL', 'Shell Oil');
    insert into customers values ('BP', 'British Petrolium');
    insert into customers values ('MOB', 'Mobile');

    I added the DataGridView, set the BindingSource, and DataSet to match the database.  I ran the code you provided without the added getpsqlcommands and it worked correctly.  It did not throw any exceptions when deleting the "Shell" record based on your series of operations.

    Hope that helps.

  • 06-16-2012 11:12 PM In reply to

    Re: VB.NET 2005 - datatable.update

    I very much appreciate you testing this; Can you please endulge me by confirming the following as I would just like to ensure we have performed the same actions.

    1.  The cust_code is your database is set as a primary key (the exception I get is "the record has a key field containing a duplicate value")

    2. When you reload the database table after performing the series of actions, the expected records are there (BP, KFC)

    3. After each of the individual steps below, you are calling the save_button routine.

    In the editable datagrid;
    1. remove the row with PK = MOB -> save_button -> Database correctly updates
    2. add a new row with PK = KFC -> save_button -> Database correctly updates
    3. remove row with PK = SHELL -> save_button -> Database exception occurs

     


    Is it possible to use the ADO.NET 3.5.0.1820 with pervasive 9.5 ?

     

     

  • 06-16-2012 11:40 PM In reply to

    Re: VB.NET 2005 - datatable.update

    When I first ran it, I did not have any indexes.  I added a unique index on the cust_code field, reset to the original data, and tried again.  I performed the steps you described clicking the save button each time.  I stopped and restarted the application and got the expected records.  I did not get the exception you are getting.

    It is not possible to use the 3.5.0.1820 provider with PSQL 9.5.  PSQL 9.5 only supports the 3.0.x.x providers. PSQL v10 added the PSQL 3.2 provider and v11 added the 3.5 provider.  I would strongly suggest upgrading to PSQL v11.  It is supported by Pervasive where v9.5 has been unsupported for over 2 years.  What I would suggest would be to download a trial of the v11 Workgroup engine, install it on a test machine and try with the newer engine and newer provider. 

  • 06-17-2012 11:29 PM In reply to

    Re: VB.NET 2005 - datatable.update

    Interesting development . . . As you suggested, I set up a new test machine running PSQL v11. On this system I also installed VS 2005. I copied over my test code and added the ADO.NET 3.5 provider. In this environment, the code worked as desired (like it did with you) producing no errors when performing "step 3". As curiosity enveloped me, I then modified the code to point to my original test server (so I'm now trying ADO.NET3.5 provider to PSQL v9.5) and behold - it worked! I was able to connect to the database, add, delete and modify records - and . . . . . it produced no fault when performing "step 3" !!! So then . . . I removed the ADO.NET3.5 reference and added the ADO.NET3.0 reference, modified the code to point back to the PSQL v11 server (so now ADO.NET3.0 provider to PSQL v11) - I was able to connect to the database, add, delete and modify records and - performing step 3 produces the fault ! Could I ask if you could please try removing the ADO.NET3.5 reference from the code you tested for me and add the 3.0 reference to verify this result ? Many thanks.
  • 06-17-2012 11:37 PM In reply to

    Re: VB.NET 2005 - datatable.update

    Clarification - note the version of our PSQL v9.5 is 9.71.010
  • 06-18-2012 6:20 AM In reply to

    Re: VB.NET 2005 - datatable.update

     On my v11 install, I do not have a 3.0 provider.  I have a 3.2 provider.  If I change the project to that provider, it still works for me.  From what I can find, the latest 3.0 provider was 3.0.0.27 and it was released in January 2009.  The next update was in April 2009 and at that point, the provider was version 3.2.  By that point, PSQL v10 had been out for 2 years so the 3.2 provider was only included in a v10 update.  Can you confirm it works with the 3.2 provider?  I cannot confirm your behavior because I do not have a 3.0 provider to test with.

  • 06-18-2012 7:59 PM In reply to

    Re: VB.NET 2005 - datatable.update

    I have confirmed that the 3.2 provider also works on my test system. Am I able to provide you with the ADO.NET 3.0 pervasive.data.sqlclient.dll file to test this? I could zip and email you this file . . .
  • 06-18-2012 8:31 PM In reply to

    Re: VB.NET 2005 - datatable.update

    I was able to find a copy of the 3.0.0.20 (one of the last 3.0) DLL and tried it.  It failed with a different error (Object not set to an instance of an object) but still failed.

    My suggestion:  Because PSQL v9.x is unsupported, the 3.0 provider is also unsupported.  If you want a fix, you are going to need to upgrade to either v10 (unsupported) or v11 and use the 3.2 or 3.5 provider.  

  • 06-18-2012 8:58 PM In reply to

    Re: VB.NET 2005 - datatable.update

    Can you confirm if it was at "step3" that you received this error?
  • 06-18-2012 10:54 PM In reply to

    Re: VB.NET 2005 - datatable.update

     Yes. It was on step 3.

  • 06-18-2012 11:33 PM In reply to

    Re: VB.NET 2005 - datatable.update

    Thanks for your help in proving my sanity and verifying there is indeed an issue. Despite 9.5 no longer being supported, I have tried "submitting a defect" in the pervasive support page anyway to draw attention to this. I am sure there are other developers out there who are still using the ADO 3.0.x providers but are unaware of this potential issue. Do you think It's unwise to use the 3.2 provider with V9.5 - even though it appears to work. As much as I would like to, I am not in a position to simply upgrade the database to a newer version.
  • 06-19-2012 7:37 AM In reply to

    Re: VB.NET 2005 - datatable.update

     According to my notes, the 3.2 provider was not released until PSQL v10 SP2 in August 2009.  PSQL v9 was no longer available after July 1, 2009, and went into transition support (no more fixes) the same day. That means Pervasive never tested the 3.2 provider with PSQL v9.x. 

    It might work today and it might work tomorrow but it might stop working after that.   Personally, I would not use the 3.2 provider with 9.5 because it was never tested, supported, or recommended by Pervasive. 

Page 1 of 2 (19 items) 1 2 Next >