# Activerecord-sqlserver-adapter nvarchar datatype length

**URL:** <https://www.ruby-forum.com/t/activerecord-sqlserver-adapter-nvarchar-datatype-length/173602>\
**Category:** Rails\
**Created:** [August 11, 2009, 10:53pm UTC](https://www.ruby-forum.com/t/activerecord-sqlserver-adapter-nvarchar-datatype-length/173602 "2009-08-11T22:53:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvin98115](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@calvin98115](https://www.ruby-forum.com/u/calvin98115)\
**Post date:** [August 11, 2009, 10:53pm UTC](https://www.ruby-forum.com/t/activerecord-sqlserver-adapter-nvarchar-datatype-length/173602/1 "2009-08-11T22:53:21Z")

</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 first\_name column is  
created has a length of 2 rather than 10. 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

Does anyone know how I can set the maximum length of the nvarchar data  
type successfully?

Thanks in advance, Calvin.
