Getting General error: 4004 General SQL Server error:

帅比萌擦擦* 提交于 2020-01-02 17:15:08

问题


I am trying to fetch data from my database in Laravel, however I am getting a "General error: 4004 General SQL Server error:"

I'm using Laravel-5 with MSSQL. If I use the DB object to fetch data from MSSQL I am not able to fetch xml and nvarchar fields,

I found a usefull link below, but to implement this I have to rewrite all my queries. Is there any other way?

https://gullele.wordpress.com/2010/12/15/accessing-xml-column-of-sql-server-from-php-pdo


回答1:


Please try :

 $handle = getHandle();
 $handle->exec('SET QUOTED_IDENTIFIER ON');
 $handle->exec('SET ANSI_WARNINGS ON');
 $handle->exec('SET ANSI_PADDING ON');
 $handle->exec('SET ANSI_NULLS ON');
 $handle->exec('SET CONCAT_NULL_YIELDS_NULL ON');

OR

You can also check the server configuration: check the "/etc/freetds.conf " file and change the tds version and add client charset then in php.ini please check mssql.charset and default_charset

in /etc/freetds.conf :

;tds version = 4.2
tds version = 8.0
client charset = UTF-8

In php.ini :

mssql.charset = "UTF-8"
default_charset = "utf-8"



回答2:


The most important information for everybody else is the answer to the question: What does the error 4004 (severity 16) mean?

Error 4004: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier.

(Source)

In my case, I had to cast a STUFF() clause to VARCHAR(MAX) to resolve the error, after migrating to SQL Server 2016 and setting tds version = 7.4.



来源:https://stackoverflow.com/questions/36428649/getting-general-error-4004-general-sql-server-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!