DT_IMAGE, which is not supported. Use DT_TEXT or DT_NTEXT instead

Afternoon,

I’ve been asked to export a load of tables to CSV files. I’m trying to use SQL Server Import and Export Wizard, the error im getting is:

Error 0xc0208030: Data Flow Task 1: The data type for "input column "CD_Document" (44)" is DT_IMAGE, which is not supported. Use DT_TEXT or DT_NTEXT instead and convert the data from, or to, DT_IMAGE using the data conversion component. (SQL Server Import and Export Wizard)

The error makes sence, I cannot have binary data in a CSV… As the error suggests I’ve gone back a few steps and in the ‘edit mappings‘ changed the requested collumn output to both DT_TEXT and DT_NTEXT… I keep getting the same error message….

Head scratching here, I must be doing something wrong but not sure what….. Any ideas?

Thanks

**If possible, replace deprecated SQL Server `image` columns with: VARBINARY(MAX)**

**Microsoft deprecated `image`, `text`, and `ntext` years ago.**

SELECT
*,
CONVERT(VARCHAR(MAX), CD_Document, 1) AS CD_Document_Text
FROM YourTable

remove original CD_Document
export CD_Document_Text instead. :winking_face_with_tongue:

Thank you, unfortunatly I don’t have authorisation to make changes to the database & its still being used… Am I not able to do the conversion on the fly as I export?

A common workaround is to export from a query instead of directly from the table.

SELECT
    Col1,
    Col2,
    CAST(ImageColumn AS VARBINARY(MAX)) AS ImageColumn
FROM dbo.YourTable

Run the query from SSMS or from the ‘Provide a Source Query‘ in SQL Server Import & Export?

In the SQL Server Import & Export Wizard:

  1. Choose your source database
  2. Select Write a query to specify the data to transfer
  3. Paste that SELECT statement
  4. Continue with the export
1 Like

@harishgg1 Thank you & sorry…. I must be having a really stupid day today :face_with_peeking_eye:

Start ‘SQL Server Import & Export Wizard’

Select the correct Server & Database > Next

Select Flat File Destination > Browse > Choose ‘CSV‘ & type filename ‘TestExport.csv’ > Open

Tick ‘Column Names In The First Data Row‘ > Next

Select ‘Write a query to specify the data transfer‘ > Next

SELECT
CD_ID,
CD_CID,
CAST(CD_Document AS VARBINARY(MAX)) AS CD_DocumentVARBIN,
CD_DocName,
CD_DateAdded
FROM Complaints_Documents

Parse > Statement Is valid > Next > Next > Finish

I’m getting the same error :thinking:

Error 0xc0208030: Data Flow Task 1: The data type for "input column "CD_DocumentVARBIN" (44)" is DT_IMAGE, which is not supported. Use DT_TEXT or DT_NTEXT instead and convert the data from, or to, DT_IMAGE using the data conversion component.
(SQL Server Import and Export Wizard)

hi

other ways to BYPASS = SSIS Import/Export

+++++++++++++++++++++++++++++++++++++++++++++++
==PowerShell

$query = @"
SELECT
    ID,
    Name,
    CAST(ImageColumn AS VARBINARY(MAX)) AS ImageColumn
FROM YourTable
"@

Invoke-Sqlcmd `
    -ServerInstance "YOUR_SERVER" `
    -Database "YOUR_DATABASE" `
    -Query $query |
Export-Csv "C:\temp\output.csv" -NoTypeInformation

++++++++++++++++++++++++++++++++++++++++++++++++++++
==Python

import pyodbc
import pandas as pd

# SQL Server connection
conn = pyodbc.connect(
    "DRIVER={SQL Server};"
    "SERVER=YOUR_SERVER;"
    "DATABASE=YOUR_DATABASE;"
    "Trusted_Connection=yes;"
)

# Convert IMAGE column to VARBINARY(MAX)
query = """
SELECT
    ID,
    Name,
    CAST(ImageColumn AS VARBINARY(MAX)) AS ImageColumn
FROM YourTable
"""

# Read into dataframe
df = pd.read_sql(query, conn)

# Export CSV
df.to_csv("output.csv", index=False)

print("Export complete")

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
==Export From a VIEW

Create a view that converts the problematic columns first.


CREATE VIEW dbo.ExportViewAS 
SELECT    ID,    Name,    CAST(ImageColumn AS VARBINARY(MAX)) AS ImageColumn
FROM dbo.YourTable

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
== Use bcp Command Line Tool

bcp is faster and handles weird datatypes better than the wizard.

bcp "SELECT ID, Name,CAST(ImageColumn AS VARBINARY(MAX)) FROM YourDatabase.dbo.YourTable"queryout "C:\temp\export.csv" ^-c -t, -T -S YOURSERVER

++++++++++++++++++++++++++++++++++++++++++++++++++++++++
== Export as XML

SELECT    
     ID,    Name,    CAST(ImageColumn AS VARBINARY(MAX)) AS ImageColumn
FROM YourTable 
    FOR XML PATH('row'), ROOT('data')

Then later convert XML → CSV using Python.

CSV files are text, you cannot put binary in text!

If you want to place a binary column into a CSV file you will need to encode it as text first. Base64 is a common way to do this - it increases the size by about a third. SQL2025 has a BASE64_ENCODE() function otherwise you will need to use XML:

As pointed out you can’t save images to a csv file. What is the objective of exporting to csv? You need to look at what is going to happen to the csv files i.e. are they going to be imported to sql server or to something else.

If they are going to be imported to sql server probably csv isn’t the best format so that’s probably not the case.

For importing to something else you need to look at the format that is supported by the end product. You might need to convert images to something that can be decoded by the end product, omit them or extract them separately. I often add a link to the file extracted then save the image separately with the filename reflecting the link (that’s the way you had to store them in older versions). You might have other issues with data types depending on the ultimate destination.