Ruby Connection SQL Server Database configuration tutorial

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.