dotnet / runtime

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

An OleDbCommand.Prepare() method throws the System.Data.OleDb.OleDbException: 'The parameter is incorrect.' exception #66

Closed maryamariyan closed 4 years ago

maryamariyan commented 4 years ago

The following code under the .NET Core 3 causes the System.Data.OleDb.OleDbException: 'The parameter is incorrect.' exception, but under .NET Framework, it works fine:

Code

        using (OleDbCommand command = new OleDbCommand()) {
            command.Connection = connection;
            command.CommandText = "insert into sales (id, units, cost_per_unit, discount, total_cost, sale_date, productId, RegionId, ChannelId, SectorId) values (@id, @units, @cost_per_unit, @discount, @total_cost, @sale_date, @productId, @RegionId, @ChannelId, @SectorId)";
            command.Parameters.AddRange(
                new OleDbParameter[] {
                    new OleDbParameter("@id", OleDbType.Integer),
                    new OleDbParameter("@units", OleDbType.Integer),
                    new OleDbParameter("@cost_per_unit", OleDbType.Integer),
                    new OleDbParameter("@discount", OleDbType.Integer),
                    new OleDbParameter("@total_cost", OleDbType.Integer),
                    new OleDbParameter("@sale_date", OleDbType.Date),
                    new OleDbParameter("@productId", OleDbType.Integer),
                    new OleDbParameter("@RegionId", OleDbType.Integer),
                    new OleDbParameter("@ChannelId", OleDbType.Integer),
                    new OleDbParameter("@SectorId", OleDbType.Integer)
                }
            );
            command.Prepare();

Call Stack

System.Data.OleDb.dll!System.Data.OleDb.OleDbCommand.ProcessResults(System.Data.OleDb.OleDbHResult hr)  Unknown
System.Data.OleDb.dll!System.Data.OleDb.OleDbCommand.ApplyParameterBindings(System.Data.Common.UnsafeNativeMethods.ICommandWithParameters commandWithParameters, System.Data.OleDb.tagDBPARAMBINDINFO[] bindInfo)   Unknown
System.Data.OleDb.dll!System.Data.OleDb.OleDbCommand.CreateAccessor()   Unknown
System.Data.OleDb.dll!System.Data.OleDb.OleDbCommand.InitializeCommand(System.Data.CommandBehavior behavior, bool throwifnotsupported)  Unknown
System.Data.OleDb.dll!System.Data.OleDb.OleDbCommand.Prepare()  Unknown
OleDbIssue.dll!OleDbIssue.SalesGenerator.Generate(System.Data.OleDb.OleDbConnection connection, System.DateTime startDate, int daysCount) Line 77   C#
OleDbIssue.dll!OleDbIssue.SalesGenerator.Run(string connectionString) Line 147  C#
OleDbIssue.dll!OleDbIssue.Program.Main(string[] args) Line 8    C#
maryamariyan commented 4 years ago

this is only for testing labeler please ignore otherwise