Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8430147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:31:47+00:00 2026-06-10T05:31:47+00:00

We have a SQL Server table with varchar and nvarchar max columns like this:

  • 0

We have a SQL Server table with varchar and nvarchar max columns like this:

CREATE TABLE [dbo].[MyTable](
  :
  [MyBigUnicodeColumn] [nvarchar](max) NULL,
  [MyBigAnsiColumn]    [varchar](max) NULL,
  :

When creating the mapping (hbm.xml) files, the documentation says to use StringClob as the type attribute for large objects with a database type of DbType.String, but it doesn’t say what to do if the database type is DbType.AnsiString.

<class name="MyTable" table="MyTable" lazy="false">
  :
  <property name="MyBigUnicodeColumn" type="StringClob" />
  <property name="MyBigAnsiColumn" type="????" />
  :

This is for NHibernate 3.3.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:31:49+00:00Added an answer on June 10, 2026 at 5:31 am

    You can map them just as string or AnsiString.

    <property name="MyBigUnicodeColumn" type="string" length="1000000"/>
    <property name="MyBigAnsiColumn" type="AnsiString" length="1000000" />
    

    Whenever the length is larger then 4000 or 8000 respectively, NH creates an nvarchar(max) or varchar(max).

    I may be that the length is used for sql parameters and that it is truncated to the specified length (it depends on the NH version you are using, there had been some changes). So better specify it large enough.


    Edit: Unfortunately, it doesn’t work with the AnsiString the same as with normal strings. I read some NH code and found the following:

    varchar(max) is supported by the dialect from SQL Server 2005 on.

    MsSql2000Dialect.cs, line 205

    RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForLengthLimitedAnsiString, "VARCHAR($l)");
    

    MsSql2005Dialect.cs, line 19:

    RegisterColumnType(DbType.AnsiString, SqlClientDriver.MaxSizeForAnsiClob, "VARCHAR(MAX)");
    

    It registers varchar(max) as the sql type to choose when an AnsiString is mapped larger then 8000.

    In the SqlClientDriver.cs you can see that it implements “blobs” in the params for strings, but not for ansi strings (line 135):

    case DbType.AnsiString:
    case DbType.AnsiStringFixedLength:
        dbParam.Size = MaxSizeForLengthLimitedAnsiString;
        break;
    // later on
    case DbType.String:
    case DbType.StringFixedLength:
        dbParam.Size = IsText(dbParam, sqlType) ? MaxSizeForClob : MaxSizeForLengthLimitedString;
        break;
    

    It always puts 8000 as the limit of the parameter of type AnsiString.

    Because of the inconsistency between the driver and the dialect, I would call it a bug.

    Because the bug happens on all AnsiStrings, it doesn’t help to specify the sql-type in the mapping (NH is able to choose the correct sql type). You need to use the workaround proposed in the thread you started on the NH forum:

    <property name="MyBigAnsiColumn" type="StringClob" sql-type="VARCHAR(max)" /> 
    

    I reported it as a bug: https://nhibernate.jira.com/browse/NH-3252

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data model like this in SQL Server: table Note - varchar
Ok I'm using SQL Server 2008 and have a table field of type VARCHAR(MAX)
I have a sql server table: CREATE TABLE [Workflow].[MilestoneDate]( [MilestoneDateId] [int] IDENTITY(1,1) NOT NULL,
I have SQL Server 2008 with a table called ProductCategories designed like this: Id
I have 5 columns in my SQL Server 2008 table: id INT name VARCHAR(100)
I have a SQL Server 2008 database table with three varchar Columns - Col1,
I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a SQL Server table which has 625 columns created with different datatypes
I have a SQL Server table with 2 columns, Code and CodeDesc. I want
i have this procedure for inserting rows in tables(sql server 2005) CREATE PROCEDURE ans_insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.