dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.25k stars 4.73k forks source link

System.Data.OleDb exception: OleDbDataAdapter internal error: invalid row set accessor: Ordinal=3 Status=UNSUPPORTEDCONVERSION. #29650

Closed ErikEJ closed 1 year ago

ErikEJ commented 5 years ago

Using .NET Core System.Data.OleDb with the SQL Server Compact provider throws this error, when reading ntext and image columns (BLOB type columns)

     OleDbDataAdapter internal error: invalid row set accessor: Ordinal=3 Status=UNSUPPORTEDCONVERSION.

Call stack:

   at System.Data.OleDb.RowBinding.CreateAccessor(IAccessor iaccessor, Int32 flags, ColumnBinding[] bindings)
   at System.Data.OleDb.OleDbDataReader.CreateAccessors(Boolean allowMultipleAccessor)
   at System.Data.OleDb.OleDbDataReader.BuildMetaInfo()
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.OleDb.OleDbCommand.ExecuteReader()
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\...\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 32

(This is not a new problem, .NET Framework OleDb threw the same exception)

Repro code:

            var path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var myConnectionStringSQL = $"Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;Data Source={path}\\NorthwindEF7.sdf;";

            using (var conSQL = new OleDbConnection(myConnectionStringSQL))
            {
                using (var cmdSQLQuery = new OleDbCommand())
                {
                    conSQL.Open();

                    using (var cmdSQL = new OleDbCommand())
                    {
                        cmdSQL.CommandType = CommandType.Text;
                        cmdSQL.Connection = conSQL;

                        //This fails
                        cmdSQL.CommandText = "SELECT [CategoryID] ,[CategoryName] ,[Description] ,[Picture] FROM [Categories];";

                        //This works
                        //cmdSQL.CommandText = "SELECT [CategoryID] ,[CategoryName] FROM [Categories]";

                        var reader = cmdSQL.ExecuteReader();
                        reader.Read();
                    }
                }
            }

Table schema:

-- Script Date: 24/05/2019 09:44  - ErikEJ.SqlCeScripting version 3.5.2.80
CREATE TABLE [Categories] (
  [CategoryID] int IDENTITY (9,1) NOT NULL
, [CategoryName] nvarchar(15) NOT NULL
, [Description] ntext NULL
, [Picture] image NULL
);
GO
ALTER TABLE [Categories] ADD CONSTRAINT [PK_Categories] PRIMARY KEY ([CategoryID]);
GO
CREATE INDEX [CategoryName] ON [Categories] ([CategoryName] ASC);
GO

I have attached a repro, install the SQL Server Compact 4.0 runtime MSI if it is not already installed.

ConsoleApp1.zip

ErikEJ commented 1 year ago

Closing as SQL Server Compact is out of support