Skip to main content
Participant
May 10, 2007
Question

Read nvarchar(max) field in SQL 2005 system views

  • May 10, 2007
  • 3 replies
  • 827 views
In SQL Query Analyzer or Management Studio, connect to a SQL 2005 server, and execute the following query:

select top 5 definition from sys.default_constraints

The result is something like

definition
-----------------
(0)
('')
('')
(0)
(0)

(5 row(s) affected)


Now try the same thing in coldfusion. (Of course, you will have to use your own datasource name):
---------- start of code ----------
<cfquery name="GetConstraintDefinition" datasource="sqlchap">
select top 5 definition from sys.default_constraints
</cfquery>
<cfdump var="GetConstraintDefinition">
<cfdump var=#GetConstraintDefinition#>
---------- end of code ----------

When run, the result is something like this:

GetConstraintDefinition query - Top 5 of 5 Rows
DEFINITION
1 [empty string]
2 [empty string]
3 [empty string]
4 [empty string]
5 [empty string]


Can anyone duplicate this misbehavior, and possibly suggest why this might be happening? The "definition" field in sys.default_constraints is an nvarchar(max) field. I have tried checking various datasource options without success. Even more interesting is that if I select an nvarchar(max) field out of one of my own tables, the data comes back just fine.


I am running ColdFusion MX version 7,0,2,142559 on Windows XP. It doesn't seem to matter whether I use the Microsoft SQL Server 2005 JDBC Driver, or the standard SQL Server Driver.

Any ideas welcome!
This topic has been closed for replies.

3 replies

Participant
May 15, 2007
It seems to occur with all sys. views. At least, I tested it with the following 2 statements:

select top 5 definition from sys.check_constraints
select top 5 definition from sys.all_sql_modules

and ColdFusion doesn't return the nvarchar(max).


If I create a table VarcharTest (col1 varchar(max), col2 nvarchar(max)) and put some data into it, the data comes back OK in coldfusion. For example

select col1, col2 from VarcharTest

returns the data. If I create a view on the table and select from it, that also works.

I wonder what is causing this....
Participant
May 11, 2007
Thanks for the suggestion, Phil.

I did actually try that; but it didn't help the situation.

The odd thing is that it's only an issue with the system views!
Inspiring
May 13, 2007
Does this occur with any of the sys. views, or just with default_constraints? (Sorry I can't duplicate this; I'm a few CF versions behind)
Inspiring
May 11, 2007
Hi parmstrong,

Just a thought: have you tried CASTing the field as, say, nvarchar(128)?