nvarchar(max) size gets set to 1

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
11/24/2009 7:32:53 PM
Gravatar
Total Posts 3
-d

nvarchar(max) size gets set to 1

I have a column in my Sql2005 db that is an nvarchar(max).   The DBObject data class correctly defines the parameter with a length of -1.  However, once it gets into the SqlParameterHelper class' DefineSqlParameter method, the parameter value gets added to the parameter array, and no size is set, so the size defaults to 1, instead of -1.  This causes only the first character of the text to be saved to the database.  Specifically setting the size in the 

private void DefineSqlParameter(String paramName,SqlDbType type,int size,ParameterDirection dir,object value,bool sizeProvided), even if the parametersDefined boolean is true, would resolve this.  Can you verify that this is a bug, or is there something more I must do when using a nvarchar(max) column?

11/24/2009 7:43:39 PM
Gravatar
Total Posts 3
-d

Re: nvarchar(max) size gets set to 1

Actually, after more testing, specifically setting the size to -1 in teh SqlHelper class doesn't help, still only the first character gets saved to the db.

11/25/2009 10:10:16 AM
Gravatar
Total Posts 18439

Re: nvarchar(max) size gets set to 1

Hi,

I don't know what to tell you. When I implemented the data layer for SqlAzure I had to use NVarchar(max) everywhere that I was using NText in the MS SQL data layer and it works correctly on SqlAzure using the SqlParameterHelper so I have no idea why it would be different on SQL 2005 using the same approach. I would make sure you have all the service paks applied.

Example code that works from the SqlAzure data layer:

SqlParameterHelper sph = new SqlParameterHelper(GetConnectionString(), "mp_HtmlContent_Insert", 13);

sph.DefineSqlParameter("@ItemGuid", SqlDbType.UniqueIdentifier, ParameterDirection.Input, itemGuid);

sph.DefineSqlParameter("@ModuleGuid", SqlDbType.UniqueIdentifier, ParameterDirection.Input, moduleGuid);

sph.DefineSqlParameter("@ModuleID", SqlDbType.Int, ParameterDirection.Input, moduleId);

sph.DefineSqlParameter("@Title", SqlDbType.NVarChar, 255, ParameterDirection.Input, title);

sph.DefineSqlParameter("@Excerpt", SqlDbType.NVarChar, -1, ParameterDirection.Input, excerpt);

sph.DefineSqlParameter("@Body", SqlDbType.NVarChar, -1, ParameterDirection.Input, body);

sph.DefineSqlParameter("@MoreLink", SqlDbType.NVarChar, 255, ParameterDirection.Input, moreLink);

sph.DefineSqlParameter("@SortOrder", SqlDbType.Int, ParameterDirection.Input, sortOrder);

sph.DefineSqlParameter("@BeginDate", SqlDbType.DateTime, ParameterDirection.Input, beginDate);

sph.DefineSqlParameter("@EndDate", SqlDbType.DateTime, ParameterDirection.Input, endDate);

sph.DefineSqlParameter("@CreatedDate", SqlDbType.DateTime, ParameterDirection.Input, createdDate);

sph.DefineSqlParameter("@UserID", SqlDbType.Int, ParameterDirection.Input, userId);

sph.DefineSqlParameter("@UserGuid", SqlDbType.UniqueIdentifier, ParameterDirection.Input, userGuid);

int newID = Convert.ToInt32(sph.ExecuteScalar());

return newID;

Best,

Joe

11/25/2009 5:20:43 PM
Gravatar
Total Posts 3
-d

Re: nvarchar(max) size gets set to 1

Thanks for your response.  I found that it was the older version of CodeSmith that was doing it.  When it sees a nvarchar(max) column in the db, it creates the stored proc parameter as just nvarchar, not specifying a length.  I downloaded a trial of the latest codesmith and that worked fine, declaring the stored proc parameter as a nvarchar(max).

You must sign in to post in the forums. This thread is closed to new posts.