Configuration instances for accessing SQL Server databases in Ruby _ruby topics

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

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

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.