Solved

Overcome 8000 character varchar limit

Posted on 2004-09-03
17
564 Views
Last Modified: 2013-12-03

Our ASP.Net/VB online application allows users to create a customized query to run against a SQL Server 2000 database. The query string is created by passing parameters to a sproc which then assembles the query string and runs it.

When the user selects very many fields for return, this limit is exceeded, and one of the parameters passed from ASP.Net is truncated. Therefore the query string is not constructed and the query can't run.

This can't be the first time this has ever happened, so... what datatype can I use to pass a value when it exceeds 8000 characters? Text? User-defined data type? If so, how?

Thanks
0
Comment
Question by:k3n51mm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +2
17 Comments
 
LVL 10

Expert Comment

by:AustinSeven
ID: 11973923
text/ntext is the only option I can think of.

AustinSeven
0
 
LVL 1

Author Comment

by:k3n51mm
ID: 11974065
Well, that's nice.

How do I do it?  What I mean is, okay, so I change the datatype to text in ASP.Net. Then when I pass it to SQL Server, I have a text parameter that is holding data that I have to use in a query. How do I manipulate the text so I can use it? This query has to be dynamically created on the SQL server and then executed. Can I simply insert the test into the query string? I've been told this is not possible.
0
 
LVL 34

Expert Comment

by:arbert
ID: 11974118
Just pass multiple varchar(8000) and concat them together when you do the query string....
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 1

Author Comment

by:k3n51mm
ID: 11974155

That means dynamically adding parameters in 12 different places in the ASP code and seems too complex and inelegant. Since this is a database issue, should we really be fixing it in the business logic? Isn't there any way the SQL Server can handle this?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11974196
>>Since this is a database issue, should we really be fixing it in the business logic? <<
Correct. This is a design issue, there very rarely is a need to do this: "The query string is created by passing parameters to a sproc which then assembles the query string and runs it."

>>Isn't there any way the SQL Server can handle this?<<
Other than what arbert has suggested, not really.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11974209
Try posting your query and we may be able to give you more intelligent answers.
0
 
LVL 34

Expert Comment

by:arbert
ID: 11974228
"That means dynamically adding parameters in 12 different places in the ASP code and seems too complex and inelegant. Since this is a database issue, should we really be fixing it in the business logic? Isn't there any way the SQL Server can handle this?"

This isn't a database issue--this is a design issue--you should have known the limitations when the application was coded and coded appropriately....

0
 
LVL 18

Accepted Solution

by:
ShogunWade earned 250 total points
ID: 11974675
if the requirement is to simply execute a dynamic sql string bigger than 8000 chars take a look at

xp_exec resultset

its undocumented but this is basically how it works....

2 parameters 1) a query which returns aSQL statement  and 2nd a DB name to run it on.

eg:


xp_execresultset 'SELECT MyQuery FROM MyTable','MyDb'

the result of 'SELECT MyQuery FROM MyTable'  would form the query to execute on MyDb



0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 11974688
example:



create table b(a varchar(8000),i int)
go

insert b values ('select *',1)
insert b values ('from sysobjects',2)


master.dbo.xp_execresultset 'Select a from b order by i','pubs'

0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 11974704
using this you can "theortically" issue a command on upto 16Tb large    :)
0
 
LVL 34

Expert Comment

by:arbert
ID: 11974770
Not quite--it would still fall under the "Maximum Capacity Specifications" in books online....
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 11974789
indeed, quite correct arbert.

PS. i should have stressed in capitals the UNDOCUMENTED word.  
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 11974854
256 Meg based on default 4K packet size.   I suspect if you need a query that's bigger than that then you have bigger issues than query size ;)
0
 
LVL 1

Author Comment

by:k3n51mm
ID: 11974898

>>This isn't a database issue--this is a design issue--you should have known the limitations when the application was coded and coded appropriately....<<

How to lose points and influence people.



>>xp_execresultset 'SELECT MyQuery FROM MyTable','MyDb'<<

How to answer the frickin' question.

Thank you all
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 11974983
glad i could help k3.
0
 
LVL 34

Expert Comment

by:arbert
ID: 11975030
"How to lose points and influence people."

You also shouldn't post in the database area and post flat out that it's a database issue/problem...and you never did post your query or what you were trying to do like acperkins requested above--there are documented workarounds that you can use.....
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11976013
>>How to lose points and influence people.<<
Please take the time to re-read the EE Guidelines.  Specifically this: "Remember, the Expert helping you today is probably going to be helping you next time you post a question."

See you next time ...
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question