title: How can I insert more than 8000 characters in a VARCHAR(MAX) column with ExecuteNonQuery?
body: <p>I am trying to insert > 8000 characters (submit from a web page) via <code>ExecuteNonQuery</code> (and <code>DatabaseFactory.CreateDatabase()</code> from MS Practices Enterprise Library). The stored procedure defines the parameter as <code>VARCHAR(MAX)</code>. The column is <code>VARCHAR(MAX)</code>. In theory, 2GB of data should be able to be passed. </p>
  
  <p>What can I do to pass data > 8000? I set a breakpoint and the <code>string.Length</code> is indeed > 8K. </p>
  
  <pre><code>   public static void UpdateTerms(string terms)
     {
          Database db = DatabaseFactory.CreateDatabase();
          db.ExecuteNonQuery("uspUpdateTerms", terms);
      }
  </code></pre>
  
  <p>Stored procedure:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[uspUpdateTerms]
      @Terms VARCHAR(MAX)
  AS
    SET NOCOUNT ON
  
    INSERT INTO tblTerms(Terms)
    VALUES(@Terms)
  </code></pre>
  
  <p>Table (just to show that everything is <code>varchar(max)</code>):</p>
  
  <pre><code>CREATE TABLE [dbo].[tblTerms](
  [ID] [int] IDENTITY(1,1) NOT NULL,
  [Terms] [varchar](max) NULL,
  [DateUpdated] [datetime] NULL,
  </code></pre>
  
  <p>.</p>
  
  <p><em><strong>Update:</em></strong></p>
  
  <p>I just changed the code, and this seems to work, though I am not sure what the difference is:</p>
  
  <pre><code> public static void UpdateTerms(string terms)
   {
          Database db = DatabaseFactory.CreateDatabase();
          DbCommand cmd = db.GetStoredProcCommand("uspUpdateTerms");
          db.AddInParameter(cmd, "Terms", DbType.String, terms);
          db.ExecuteNonQuery(cmd);
   }
  </code></pre>