1.安装FreeTDS
sudo apt‐get install freetds‐dev freetds‐bin tdsodbc
2.配置FreeTDS[developer]
host = endor
port = 1433
instance = DEVELOPER # connect to a named instance
tds version = 8.0
client charset = UTF‐8
[production]
host = endor
port = 1433
tds version = 8.0
client charset = UTF‐8
sudo apt-get install sqsh
安装sqsh后可以测试FreeTDS是否配置成功
sqsh -S developer -U database_username -P database_password
测试是否能够连接上sql-server
连上数据库后,使用如下命令可对数据库进行操作。
> use project_development > go > select count(*) from people > go
3.安装 tiny_tds和activerecord-sqlserver-adapter
/opt/ruby/bin/gem install tiny_tds
/opt/ruby/bin/gem install activerecord-sqlserver-adapter
需要在工程文件的Gemfile中加入gem 'tiny_tds'
gem 'activerecord‐sqlserver‐adapter'
4.database.yml文件配置
development:
adapter: sqlserver
host: 192.168.106.62
database: drivelink_db
username: drivelink
password: drivelink
更详细的配置:
development:
adapter: sqlserver
mode: dblib
dataserver: sql2008ds
host: mydb.net
port: 1433
database: myapp_dev
username: sa
password: secret
timeout: 5000
azure: true