# Activerecord-sqlserver-adapter nvarchar datatype length

**URL:** <https://www.ruby-forum.com/t/activerecord-sqlserver-adapter-nvarchar-datatype-length/173617>\
**Category:** Rails\
**Created:** [August 12, 2009, 3:57am UTC](https://www.ruby-forum.com/t/activerecord-sqlserver-adapter-nvarchar-datatype-length/173617 "2009-08-12T03:57:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubynewbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rubynewbie](https://www.ruby-forum.com/u/rubynewbie)\
**Post date:** [August 12, 2009, 3:57am UTC](https://www.ruby-forum.com/t/activerecord-sqlserver-adapter-nvarchar-datatype-length/173617/1 "2009-08-12T03:57:10Z")

</div>

I’ve recently installed this adapter in hope that I can work with  
utf-8  
encoding using the SQL Server nvarchar data type. I’ve installed and  
followed the steps detailed at this uri:  
[http://github.com/adzap/rails-sqlserver-adapter/tree/master](http://github.com/adzap/rails-sqlserver-adapter/tree/master)

I have this following migration class definition:  
class CreateContacts \< ActiveRecord::Migration  
def self.up  
create\_table :contacts do |t|  
t.column :organization\_id, :integer, :null=\>false  
t.column :first\_name, :nvarchar, :limit=\>10, :null=\>false  
t.column :last\_name, :nvarchar, :null=\>false  
t.column :title, :string  
t.column :contact\_type\_id, :integer, :null=\>false  
t.column :fax, :string  
t.timestamps  
end  
end

```
def self.down
    drop_table :contacts
end

```

end

When I look at the generated table definition, the first\_name column  
created has a length of 2 rather than 10 as specified by the :limit  
parameter.  
In fact all of the columns of type :nvarchar get a length of 2. If I  
try what the web site  
documentation has, namely:

t.column :body2\_utf8, :nvarchar\_max # Creates nvarchar(max)  
or in my case:  
t.column :first\_name, :nvarchar\_max, :null=\>false

I get an error that says:  
DBI::DatabaseError: Execute  
OLE error code:80040E14 in Microsoft OLE DB Provider for SQL  
Server  
Column, parameter, or variable #3: Cannot find data type  
nvarchar\_max.  
HRESULT error code:0x80020009

What is the correct way to set the maximum length of the nvarchar data  
type?
