1

I would like to save html in SQL Server.

From the discussions I have seen in stackoverflow (Storing HTML in SQL Server), the recommendation is to use NVARCHAR(MAX) or VARCHAR(MAX)

However, when I try to save html in the VARCHAR(MAX) Or NVARCHAR(MAX) column, it is giving me the following error:

pyodbc.DataError: ('22018', '[22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: image is incompatible with varchar(max) (206) (SQLExecDirectW); [22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)')

How can the issue be resolved?

Steve
  • 25,806
  • 2
  • 33
  • 43
  • Need to see your code. For whatever reason your code is generating a parameter of type `image` – Dale K Mar 10 '19 at 21:46
  • It seems the parameter data type (image) is incorrect. Also, you are using the old `SQL Server` ODBC driver, which is unaware of data types introduces since SQL 2000. – Dan Guzman Mar 10 '19 at 21:48
  • Datatype of the "html" column is varchar(max) here's a snippet of the code document = urlopen(url, context=ctx) html = document.read() cur.execute('''Update dbo.Pages SET html=? WHERE url=?''', (html, url ) ) here's the error message: cur.execute('''Update dbo.Pages SET html=? WHERE url=?''', (html, url ) ) pyodbc.DataError: ('22018', '[22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: image is incompatible with varchar(max) (206) (SQLExecDirectW); [22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)') – Wengkit Tan Mar 11 '19 at 21:11
  • would it help if i use "soup" or "testhtml" as the data source instead of "html"? soup = BeautifulSoup(html, "html.parser") testhtml = memoryview(html) – Wengkit Tan Mar 11 '19 at 21:11
  • i installed the ODBC Driver version 17 – Wengkit Tan Mar 11 '19 at 22:15
  • cur.execute('''Update dbo.Pages SET html=? WHERE url=?''', (html, url ) ) pyodbc.DataError: ('22018', '[22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: image is incompatible with varchar(max) (206) (SQLExecDirectW); [22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)') – Wengkit Tan Mar 11 '19 at 22:15
  • error is the same – Wengkit Tan Mar 11 '19 at 22:15
  • I am having the same issue using Driver=SQL Server and a None type is trying to be cast to an image on a geography field???? What is going on? – Steve May 07 '19 at 00:23
  • @Steve - The ancient `Driver=SQL Server` supports SQL Server 2000, while the geography type was introduced in SQL Server 2008. The driver does not know how to handle the geography data type because it did not exist when the driver was written. – Gord Thompson May 07 '19 at 00:47
  • @GordThompson what is the proper token to pass to use the most recent driver? – Steve May 07 '19 at 00:55
  • 1
    @Steve - Right now the latest version of msodbcsql is `DRIVER=ODBC Driver 17 for SQL Server`. Of course, you'll need to [install it](https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017) before you can use it. – Gord Thompson May 07 '19 at 01:18

0 Answers0