Cannot import flat file to Azure Data Studio

Note Thanita 6 Reputation points
2022-04-30T02:39:01.913+00:00

Hi,

I'm using mac to run Azure Data Studio to work with SQL.

I use import wizard to import csv files. Some file can be uploaded but most of files can't and it shows like this below.

Please suggest. Thanks

✗ Microsoft.SqlServer.Prose.Import.BcpProcessException: Error inserting data into table. ---> System.InvalidOperationException: The given value 'Yes' of type String from the data source cannot be converted to type bit for Column 10 [owns_car]. ---> System.FormatException: Failed to convert parameter value from a String to a Boolean. ---> System.FormatException: String was not recognized as a valid Boolean.
at System.Boolean.Parse(ReadOnlySpan1 value) at System.Boolean.Parse(String value) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at Microsoft.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming) --- End of inner exception stack trace --- at Microsoft.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming) at Microsoft.Data.SqlClient.SqlBulkCopy.ConvertValue(Object value, _SqlMetaData metadata, Boolean isNull, Boolean& isSqlType, Boolean& coercedToDataFeed) --- End of inner exception stack trace --- at Microsoft.Data.SqlClient.SqlBulkCopy.ConvertValue(Object value, _SqlMetaData metadata, Boolean isNull, Boolean& isSqlType, Boolean& coercedToDataFeed) at Microsoft.Data.SqlClient.SqlBulkCopy.ReadWriteColumnValueAsync(Int32 col) at Microsoft.Data.SqlClient.SqlBulkCopy.CopyColumnsAsync(Int32 col, TaskCompletionSource1 source)
at Microsoft.Data.SqlClient.SqlBulkCopy.CopyRowsAsync(Int32 rowsSoFar, Int32 totalRows, CancellationToken cts, TaskCompletionSource1 source) at Microsoft.Data.SqlClient.SqlBulkCopy.CopyBatchesAsyncContinued(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource1 source)
at Microsoft.Data.SqlClient.SqlBulkCopy.CopyBatchesAsync(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource1 source) at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet internalResults, CancellationToken cts, TaskCompletionSource1 source)
at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletionSource1 source) 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 Microsoft.SqlServer.Prose.Import.BcpTextSynthesis.InsertIntoDB(String inputFilePath, String tableName, String schemaName, IReadOnlyList1 columnInfo, SqlConnection connection, Int32 batchSize, SqlTransaction transaction, IList1 allFinalTransformations, IList1 allFinalTransformationColumns, IList1 allFinalColNames) --- End of inner exception stack trace --- at Microsoft.SqlServer.Prose.Import.BcpTextSynthesis.InsertIntoDB(String inputFilePath, String tableName, String schemaName, IReadOnlyList1 columnInfo, SqlConnection connection, Int32 batchSize, SqlTransaction transaction, IList1 allFinalTransformations, IList1 allFinalTransformationColumns, IList`1 allFinalColNames)
at Microsoft.SqlServer.Prose.Import.BcpProcess.CreateTableAndInsertDataIntoDb(String connectionString, Int32 batchSize, String azureAccessToken)

Community Center Not monitored
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. DWN 11 Reputation points
    2022-06-08T15:40:40.743+00:00

    @Olaf Helper , Unfortunately, I'm getting the exact same error, but with 0s and 1s! Any suggestions?

    ✗ Microsoft.SqlServer.Prose.Import.BcpProcessException: Error inserting data into table. ---> System.InvalidOperationException: The given value '0' of type String from the data source cannot be converted to type bit for Column 4 [isInDC]. ---> System.FormatException: Failed to convert parameter value from a String to a Boolean. ---> System.FormatException: String was not recognized as a valid Boolean.

    2 people found this answer helpful.

  2. CyrAz 5,181 Reputation points
    2022-04-30T10:38:56.103+00:00

    Seems that the column "owns_car" has defined type of "bit", which only accepts 1, 0 or NULL as values; and the dataset you're trying to import contains the value "Yes".
    See https://learn.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-ver15

    0 comments No comments

  3. Olaf Helper 47,436 Reputation points
    2022-05-02T11:36:13.847+00:00

    the given value 'Yes' of type String from the data source cannot be converted to type bit for Column 10 [owns_car].

    You get a clear error message, SQL Server can't convert string Yes/No to bit, you have to convert it on your own, like

    SELECT CASE WHEN sourceColumn = 'Yes' THEN 1 ELSE 0 END AS owns_car
    
    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.