Any one please help me out. I am syncing sql server to client using MS Sync Framework. I am getting this exception at syncOrchestrator.Synchronize();
Failed to execute the command 'BulkInsertCommand' for table ‘xyz'; the transaction was rolled back. Ensure that the command syntax is correct.
Inner Exception is:
Violation of PRIMARY KEY constraint 'PK__#B1CF471__ECD9228532A93525'. Cannot insert duplicate key in object 'dbo.#changeTable'. The duplicate key value is (0). The data for table-valued parameter \"#changeTable\" doesn't conform to the table type of the parameter. The statement has been terminated.
There is a store procedure that using above object 'dbo.#changeTable', but I don't know what to do with that??
Related
We have a stored procedure in SQL Server which inserts data from a staging table into a fact table. This is first joined onto various dimension tables to get their id columns.
Intermittently, it will throw the following error:
('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot bulk load. The bulk data stream was incorrectly specified as sorted or the data violates a uniqueness constraint imposed by the target table. Sort order incorrect for the following two rows: primary key of first row: (305603, 0xedd9f90001001a00), primary key of second row: (245634, 0x0832680003003200). (4819) (SQLExecDirectW)')
(The two rows mentioned in the error message usually change each time the error occurs)
The fact table doesn't have any primary key or clustered index, although it does have a few non-clustered indexes, so the error message is really confusing me.
The dimension tables DO have primary keys, but the fact table has no foreign keys related to them.
I have searched for hours on the internet but don't seem to have found a solution.
Does anybody know why I would receive such an error in this case? any help would be appreciated. We are using Azure SQL database.
I am aware that the database is badly designed however it was created before my time.
I use Nife 1.13.2 for build ETL process between Oracle and PostgresQL.
There is an ExecuteSQL processor for retrieving data from Oracle and a PutDatabaseRecord processor for inserting data to PostgresQL's table. In PostgresQL's processor there configured INSERT_IGNORE option. The name of key column in both tables is DOC_ID. But due to insert operation, from some reason, Nifi generate mistaken name of the column as it is seen from follow line: ON CONFLICT (DOCID) DO NOTHING
Here is whole error:
Failed to put Records to database for StandardFlowFileRecord[uuid=7ff8189a-2685-4f
9a-bab6-d0bc9b4f7ae0,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1623310567664-311, container=default, section=311], offset=604245, length=610377],offset=211592,name=7ff8189a-2685-4f9a-bab6-d0bc9b4f7ae0,size=6106].
Routing to failure.: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO src.rtl_sales(doc_id, complete, out_sale_sum_disc, kpp_num, org_id, kpp_status, im) VALUES (1830335807, '2020-06-12 +03', '530.67'::numeric, 565900, 62, 4, NULL
) ON CONFLICT (DOCID) DO NOTHING was aborted: ERROR: column "docid" does not exist
Here is table in PostgresQL:
Here is part of FlowFile from the queue:
What is wrong with me or Nifi?
OK, so it must be Translate Field Names -> False in PutDatabaseRecord:
Is it possible to raise a custom message in SQL Server when trying to delete an entity with a foreign key violation? I use EntityFramework 6 and I would like to have a custom SqlException raised by sql server to better specify the error. Today EntityFramework raises the exception caused by sql server and I don't want to parse the general sql exception messages to specify such issues.
This is the exception:
System.Exception: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: The MERGE statement conflicted with the REFERENCE constraint "FK_My_ForeignKey"....
I think about something like this:
...
CONSTRAINT [FK_My_ForeignKey] FOREIGN KEY([Code]) REFERENCES [dbo].[MyTable] ([Code]) ON DELETE No Action AND RAISEERROR('MyCustomFKViolationError')
...
Or is there a better way to handle this via the `EntityFramework?
Changing this behavior in SQL Server would be a little strange. You can overcome this problem simply in .Net/Entity Framework. Just look at this post to overcome it:
https://stackoverflow.com/a/2403361/1666800
I would like to know is it possible to return a DB ERROR code from trigger, rather than Custom exception created with RAISE_APPLICATION_ERROR. I have some requirement where i need to return an DB ERROR code like 1 for Unique Constraint. I have a purpose to ask this, because for some reason with some hash based partition we are not creating unique constraints on table and rather have one trigher with which i want to return Unique constraint as an error code after checking if the record exists in DB.
You can use:
RAISE DUP_VAL_ON_INDEX;
Only in this case you can't pass any arguments to this error and you will get:
ORA-00001: unique constraint (.) violated
I want to delete all rows from table in sql server 2000 but whenever I want to delete manually or with query it shows error. In help tab it shows ODBC error: <0s>.
My table contains some '0' values but its datatype is String. Is that's the reason for this
error.
code is:
stat2=conn.createStatement();
stat2.executeUpdate("Delete * from pat.dbo.PHPL");
"Key column information is insufficient or incorrect. Too many rows were affected by update" that's warning and when click help it shows: ODBC error: <0s>. An ODBC error has been generated. You might have deleted a record that has a foreign key value related to it, or you might have violated a check constraint. For details, refer to your ODBC documentation.
Use
Truncate Table PHPL
I think you have duplicate identities, check you are not allowing duplicates on this column.