Skip to content

Import-DbaCsv: Issue with scientific notification import to decimal fields #35

@mbentham

Description

@mbentham

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

PSMessageDetails :
Exception : System.Exception: CSV parse error ---> System.Management.Automation.MethodInvocationException:
Exception calling "WriteToServer" with "1" argument(s): "CSV parse error" --->
Dataplat.Dbatools.Csv.CsvParseException: CSV parse error
at Dataplat.Dbatools.Csv.Reader.CsvDataReader.HandleParseError(Exception ex, String line)
in D:\a\dbatools.library\dbatools.library\project\dbatools\Csv\Reader\CsvDataReader.cs:line
1807
at Dataplat.Dbatools.Csv.Reader.CsvDataReader.ReadSequentialDirect() in
D:\a\dbatools.library\dbatools.library\project\dbatools\Csv\Reader\CsvDataReader.cs:line 1611
at Dataplat.Dbatools.Csv.Reader.CsvDataReader.Read() in
D:\a\dbatools.library\dbatools.library\project\dbatools\Csv\Reader\CsvDataReader.cs:line 1476
at Microsoft.Data.SqlClient.SqlBulkCopy.ReadFromRowSourceAsync(CancellationToken cts)
at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerInternalAsync(CancellationToken ctoken)
at Microsoft.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32 columnCount,
CancellationToken ctoken)
at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(IDataReader reader)
at CallSite.Target(Closure , CallSite , Object , Object )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame
frame)
at
System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
at
System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
--- End of inner exception stack trace ---
TargetObject :
CategoryInfo : NotSpecified: (:) [], Exception
FullyQualifiedErrorId : dbatools_Import-DbaCsv
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Stop-Function, : line 102446
at Import-DbaCsv, : line 45233
at , : line 1
PipelineIterationInfo : {}

Steps to Reproduce

Create a table in SQL Server with a decimal column:

CREATE TABLE [dbo].[test](
	[id] [int] NULL,
	[data] decimal(18,6) NULL
)

Create a csv file with a scientific notation number:

id,data
1,1.2345678E5

Import the CSV to the created table using the Import-DbaCsv command

Import-DbaCsv -Path .\scientific_notification.txt -SqlInstance localhost -Database DBA -Table test -EnableException

Please confirm that you are running the most recent version of dbatools

2.7.13

Other details or mentions

In older dbatools versions where Import-Csv relied on the LumenWorks library this did not produce an error and would successfully convert the scientific-notation value into a decimal

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.26100.7019
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.7019
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM-CU32-GDR) (KB5068404) - 15.0.4455.2 (X64) Oct 7 2025 21:10:15 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2022 Datacenter 10.0 (Build 20348: ) (Hypervisor)

.NET Framework Version

.NET Framework 4.8.4795.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions