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
1. Download FreeTDS Source code
2. Decompression Compile Installation:
The code is as follows |
Copy Code |
./configure--prefix=/usr/local/freetds && make && sudo make install |
Install Tiny_tds
Tiny_tds, installation and use is very simple, recommended use:
The code is as follows |
Copy Code |
sudo gem install tiny_tds----With-freetds-dir=/usr/local/freetds
|
Using TINY_TDS to access SQL Server is simple:
The code is as follows |
Copy Code |
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:
The code is as follows |
Copy Code |
Gem Install Activerecord-sqlserver-adapter
|
The configuration database.yml is as follows:
The code is as follows |
Copy Code |
Development Adapter:sqlserver Host:mydb.net Database:myapp_development Username:sa Password:secret |
Small hint, if you feel configuration trouble can use Microsoft Official ODBC driver, address as follows: http://www.microsoft.com/en-us/download/details.aspx?id=28160
Go and study it yourself.