Error -2147217887 when inserting a row into a Microsoft Access table migrated to SQL Server

Bikhod 61 Reputation points
2022-12-13T17:19:03.13+00:00

Hello,

Using the Microsoft SQL Server Migration Assistant tool, we have migrated an Access database to SQL Server 2017 but we are getting error -2147217887 when trying to insert a record into a migrated SQL Server table using ADO Recordset from VBA. The migrated table has an IDENTITY based primary key.

If we remove the IDENTITY then we don't get the error. As soon as we put the IDENTITY back on the primary key column, we get the error.

Error text: Run-Time Error '-2147217887 (80040e21)' Multiple-Step Operation Generated Errors

I found some articles mentioning changing the length of VARCAHAR fields to 250. That didn't make a difference.

Here is the migrated table DDL in SQL Server

CREATE TABLE [dbo].tblDecisionTree

Any ideas?

Microsoft 365 and Office | Access | Development
SQL Server | Other
{count} votes

4 answers

Sort by: Most helpful
  1. Bikhod 61 Reputation points
    2022-12-19T16:26:49.953+00:00

    I have found the cause of our issue. The ID column of our table is declared as an INT in SQL Server by the Access Migration Assistant tool. So, in the Access VBA code, the ADO Recordset is matching SQL Server with an Integer data type, which is VBA is limited to is limited to -32768 to +32767.

    But, the values that have been migrated from Access to SQL Sever for this column are currently t 57566 which is too big for VBA Integer.

    Solution: changed the SQL Server Identity column to be a BIGINT which meant the ADO recordset column became a LONG and now the code is working.

    1 person found this answer helpful.
    0 comments No comments

  2. YufeiShao-msft 7,146 Reputation points
    2022-12-14T02:49:47.317+00:00

    Hi @Bikhod ,

    If you use ADO to insert a new record through a client-side recordset into a SQL Server table that has a non-nullable datetime field with a default value, you may receive this error message if you do not supply a value for the datetime field

    Please check out this article, hope it can solve your issue
    https://learn.microsoft.com/en-us/troubleshoot/sql/connect/error-when-you-use-client-cursor-add-record

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. Gustav 717 Reputation points MVP
    2022-12-14T10:29:20.36+00:00

    You probably need an insert query to overwrite an identity field. Use an action query and SQL similar to:

    INSERT INTO Test ([ID]) VALUES (57633)  
    
    0 comments No comments

  4. AlphonseG 236 Reputation points
    2022-12-14T14:03:49.763+00:00

    You can't insert into a SQL Server Identity column unless you set IDENTITY_INSERT ON for the table.
    https://learn.microsoft.com/en-us/sql/t-sql/statements/set-identity-insert-transact-sql?view=sql-server-ver16

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.