Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AseCommandBuilder throwing MissingPrimaryKeyException exception #188

Open
fernandoderoia opened this issue Aug 9, 2020 · 3 comments
Open

Comments

@fernandoderoia
Copy link

fernandoderoia commented Aug 9, 2020

Hi everyone, and sorry for my english in advance....
I work for a financial institution and we have a system developed in VB.NET .NET Framework 4.6.1 working with Sybase ASE 12.5.4 (Adaptive Server Enterprise/12.5.4/EBF 13387/P/NT).
I've been trying out this library and now it seems pretty stable, especially on managing asynchronous processing, so I'm planning to replace the current Sybase.AdoNet45.AseClient.dll with this one.

But I came to an exception which I did not have on Sybase.AdoNet45.AseClient.dll. This happens when using a AseDataAdapter and AseCommandBuilder to INSERT/UPDATE a table wich has no primary key, but does have a unique index.

Debugging the soruce, it ends in this method: GetSchemaTableWithKeyInfo:

throw new MissingPrimaryKeyException("Cannot generate SQL statements if there is no unique column in the source command.");

The table script which I intend to INSERT is this:


CREATE TABLE dbo.ODEBIN  ( 
	ODB_FECNEG	datetime NOT NULL,
	ODB_NROLOG	decimal(12,0) NOT NULL,
	ODB_TIPOBJ	varchar(5) NOT NULL,
	ODB_IDEBIN	varchar(22) NOT NULL,
	ODB_TIPMOV	varchar(1) NOT NULL,
	ODB_FECORI	datetime NOT NULL,
	ODB_TIMORI	decimal(6,0) NOT NULL,
	ODB_CODIMP	varchar(1) NOT NULL,
	ODB_ORITRX	varchar(40) NOT NULL,
	ODB_ORITER	varchar(10) NOT NULL,
	ODB_ORIADI	varchar(10) NOT NULL,
	ODB_CBU   	char(22) NOT NULL,
	ODB_CUENTA	decimal(15,0) NOT NULL,
	ODB_ORDEN 	decimal(15,0) NOT NULL,
	ODB_TIPCTA	decimal(5,0) NOT NULL,
	ODB_SUCURS	decimal(5,0) NOT NULL,
	ODB_MONEDA	decimal(5,0) NOT NULL,
	ODB_CUIT  	decimal(11,0) NOT NULL,
	ODB_IMPORT	decimal(13,2) NOT NULL,
	ODB_FECPRO	datetime NOT NULL,
	ODB_ESTADO	smallint NOT NULL 
	)
ON [default] 
GO
CREATE UNIQUE NONCLUSTERED INDEX X_ODB_NRLOG
	ON dbo.ODEBIN(ODB_NROLOG)
	ON [default]
GO

Creating primary keys is not an option. Do you think you can reproduce my case ? Or should I provide more information ?
Thanks in advance

Best regards

@fernandoderoia
Copy link
Author

Below is a sample code to reproduce the case. Create the following table in the database:

CREATE TABLE TBTEST(Field1 INT, 
                    Field2 VARCHAR(20))
                    
CREATE UNIQUE INDEX IXTB_TEST ON TBTEST(Field1)

The following VB.NET code produces the exception:


     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim oCommand As New AseCommand

        Dim dsTemp As DataSet
        Dim oRow As DataRow

        Dim daTemp As AseDataAdapter
        Dim cbTemp As AseCommandBuilder

        Try

            oCommand.Connection = oConn
            oCommand.CommandText = "SELECT * FROM TBTEST WHERE 1 = 0"
            daTemp = New AseDataAdapter(oCommand)

            dsTemp = New DataSet
            daTemp.Fill(dsTemp)
            cbTemp = New AseCommandBuilder(daTemp)

            oRow = dsTemp.Tables(0).NewRow
            oRow("Field1") = 1
            oRow("Field2") = "Hello world"
            dsTemp.Tables(0).Rows.Add(oRow)

            daTemp.Update(dsTemp)
            dsTemp.AcceptChanges()

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

@ngvtien
Copy link
Contributor

ngvtien commented Sep 4, 2020

Wonder why we'd need to enforce primary key or unique index at the driver level? The driver shouldn't mandate those.

@fernandoderoia
Copy link
Author

Really don't know why.... But if intended behaviour is like Sybase.AdoNet45.AseClient.dll it should be fixed.
The exception has logic if the table has no indexes, but this is not the case...

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants