1.Edit config/database.yml.

adapter: sqlserver
dataserver : 'your host name.database.windows.net'
database: your database name
username: your user name
password: your password
azure: true
pool: 5
timeout: 5000

2.Edit Gemfile.
Change from "gem 'sqlite' " to "gem 'activerecord-sqlserver-adapter' "


3.Add a schema mapping script file in config/initializers directory.

ActiveRecord::ConnectionAdapters::SQLServerAdapter.enable_default_unicode_types = true
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'nvarchar(max)'
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'nvarchar'

 This mapping script file need for Rails 3.0.x. If rails 3.1.0 or above, no need it.

 notice:activerecord-sqlserver-adapter-3.1.1 in NougakuDo 1.1.7.
 This version can't connect SQL Azure. Because of use "DBCC useroptions" command. So must use patch. Patch is patches folder of source tree. Now commited patch in original source tree.
 notice:activerecord-sqlserver-adapter's bug fixed in NougakuDo 1.1.9.

4.rails generate scaffold post title:string body:text published:boolean  command.
- success.

5.rake db:migrate command.
- Result is error at "INSERT INTO [schema_migrations]".

6.Create a cluster index on schema_migrations.

CREATE CLUSTERED INDEX [idx_schema_migrations_version] ON [schema_migrations] ([version])


7.rake db:migrate command.
- success.

8.Create stored procedure.
- sp_MSforeach_worker and sp_MSforeachtable .

-ActiveRecord SQLServer Adaptor.
-Using tiny_tds.

Last edited Nov 9, 2011 at 1:22 AM by arai, version 12


No comments yet.