Monday, March 19, 2012

Bug, Can not create varchar(max) columns with SMO

I just want to create a varchar(max) column with SMO. My code is as follows. Instead of varchar(max), a column with datatype varchar(1) is created!!!

Table t = new Table(db, "t1");
t.Columns.Add(new Column(t, "c1", new DataType(SqlDataType.NVarCharMax)));
t.Alter();

That seems to be a bug of release version. I don't face this problem in Beta 2

Is there a workaround for that problem
This seems like bug to me also. I will file a bug against the product. As a workaround, you can execute the T-SQL directly, such as

db.ExecuteNonQuery("create table tb (id nvarchar(max))");

Peter

|||Thanks for your help.|||Just ran across the same issue. Any other workaround on this?|||Hi

I just encountered the same issue with Sql Server 2005 SP1. However, it has only happened on one computer. The problem is not reproducible on any other machines in our environment.

|||YOu should doublecheck that again, as in SP2 the following script is returned from the Scripter:

Code Snippet

USE [Northwind]

ALTER TABLE [dbo].[t1] ADD [c1] [nvarchar](max)

Jens K. Suessmeyer

http://www.sqlserver2005.de

|||The SMO library is invoked on a server that does not have Sql Server. The only Sql Server related libraries installed on the server are as follows.

XMO 9.00.1399.06 NOV 2005 Feature Pack
NATIVE CLIENT 9.00.1399.06 NOV 2005 Feature Pack
XML6.0 6.00.3890.0 NOV 2005 Feature Pack

Are there known issues with using these versions?

Thanks
|||The SMO libraries are also updated within the service packs, so it could be that the actual stack which is generating the ALTER statement was bug fixed. I posted a bug before RTM time, which was also fixed with SP1, so there can be a good chance that the version you are using 1399 = RTM has the bug which is causing the problems.

Jens K. Suessmeyer

http://www.sqlserver2005.de

|||

Actually, you can set it - it's just a bit "hidden". Set the DataType to NVarChar and set an arbitrary length value (like 100). Then set the column's DataType.MaximumLength property to -1. It is now a NVarChar(max) column.

|||Thanks

I resolved the problem by upgrading the Sql Server Management Objects from the Nov 2005 release to the Feb 2007 release.

No comments:

Post a Comment