Why does OleDb reject a query that works in MS Access?

118 Views Asked by At

I am trying to execute the query below with a C# program using Microsoft.ACE.OLEDB.12.0 to connect to an Access 2019 database. The query works when I run it in Access. How can I get it to work in my program? It fails with

Error Message:

System.Data.OleDb.OleDbException HResult=0x80040E57 Message=The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data

Query:

INSERT INTO `PlayerAwardsMart` (`tournament`, `competition`, `place`, `award`, `player_id`, `player`, `registration_group`, `team`) 

SELECT        LatestActiveTournament.label AS tournament, PlayerResultsMart.Competition AS competition, PlayerResultsMart.Rank AS place, PlayerResultsMart.Award AS award, PlayerResultsMart.ID AS player_id, 
                         PLAYER.[FIRST] + ' ' + PLAYER.[LAST] AS player, GEOCODE.CITY AS registration_group, TEAM.TEAM_NAME AS team
FROM            LatestActiveTournament, ((GEOCODE INNER JOIN
                         (PlayerResultsMart INNER JOIN
                         PLAYER ON PlayerResultsMart.ID = PLAYER.ID) ON GEOCODE.GEOCODE = PLAYER.GEOCODE) INNER JOIN
                         TEAM ON PlayerResultsMart.TeamID = TEAM.ID)
WHERE        (PlayerResultsMart.Award IS NOT NULL)
ORDER BY PlayerResultsMart.Competition, PlayerResultsMart.Rank, PlayerResultsMart.ID

Connection string:

        <add name="DataGrids.Properties.Settings.agamesConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&quot;C:\AGAMES\AGAMES.accdb&quot;;Persist Security Info=True" providerName="System.Data.OleDb"/>

I debugged my program in Visual Studio 2022 v 17.5 . I found the query that caused the exception. So, I ran that query in the actual database. It worked fine. I need to automate that in my program, though.

1

There are 1 best solutions below

0
Mike Steigerwald On

I guess I should have taken the error message more seriously. It was absolutely correct. One of my fields was too small.

Access truncated it, so the query succeeded there. I guess Microsoft.ACE.OLEDB.12.0 actually did me a favor by not truncating it.**