Passing and nvarchar(Max) parameter form Access 2013 to a SQL Server SPROC?

mlcktmguy
mlcktmguy used Ask the Experts™
on
I am writing a routine in my Access 2013 front end that calls a SPROC on SQL Server.  One of the params is a user comment that is defined as nvarchar(max) on the SQl side.

I have written access routines that call SPROCS, passing string variables but they are of a defined length.  A param statement passing to a field defined as nvarchar(30) in SQL looks like this:

    Set param6 = .CreateParameter("passedUserName", adVarChar, adParamInput, 30, passedUserName)
    .Parameters.Append param6

Open in new window


What would the syntax be when passing a param defined a nvarchar(max) in the SPROC?

I'm temporarily using
    Set param6 = .CreateParameter("passedUserName", adVarChar, adParamInput, 1000 , passedUserName)
    .Parameters.Append param6

Open in new window

but that has a fixed length of 1000.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Pass it as if it was the old nText datatype in SQL (a guess) Access 2013 doesn't understand or recognise the varchar(max) datatype.

Kelvin
Topic Advisor, Page Editor
Distinguished Expert 2018
Commented:
You might have problems with strings over 8000 long any way depending on versions/connection etc. Very long username :)

But you could use adLongVarWChar with a length of -1

cmd.Parameters.Append cmd.CreateParameter("passedUserName", adLongVarWChar, adParamInput, -1 , passedUserName)

have a read of : https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ac06f814-1814-4861-b2cd-8d5e507a7ee3/what-is-the-ado-datatype-for-nvarcharmax?forum=sqldataaccess

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial