Because of the job needs, to analyze the data stored on the SQL Server, so have to study how to use Ruby access to SQL Server, found in fact is very simple:
Install FreeTDS
Download FreeTDS Source code
Decompression Compile Installation:
Copy Code code as follows:
./configure--prefix=/usr/local/freetds && make && sudo make install
Install Tiny_tds
Tiny_tds, installation and use is very simple, recommended use:
Copy Code code as follows:
sudo gem install tiny_tds----With-freetds-dir=/usr/local/freetds
Using TINY_TDS to access SQL Server is simple:
Copy Code code as follows:
Require ' Tiny_tds '
Client = Tinytds::client.new (: username => ' Fankai ',:p assword => ' Fankai ',: Host => ' 192.168.0.1 ',:d atabase => ; ' Test ')
result = Client.execute ("SELECT top * from User");
Result.each do |row|
Puts row
End
Use Tiny_tds on ActiveRecord
This is also very simple, refer to this tutorial using Tinytds:
Copy Code code as follows:
Gem Install Activerecord-sqlserver-adapter
The configuration database.yml is as follows:
Copy Code code as follows:
Development
Adapter:sqlserver
Host:mydb.net
Database:myapp_development
Username:sa
Password:secret