1
0
mirror of https://github.com/Microsoft/sql-server-samples.git synced 2025-12-08 14:58:54 +00:00
Files
sql-server-samples/samples/connect/ruby/mac
2016-07-18 17:09:13 -07:00
..
2016-07-18 16:08:26 -07:00
2016-07-18 17:09:13 -07:00

Connect to SQL Database by using Ruby on Mac OS X (Yosemite)

[Ruby code sample] (sample_ruby_mac.rb) that runs on Mac computer running Yosemite to connect to an Azure SQL Database database.

Install the required modules

Open your terminal and install the following:

1) Homebrew: Run the following command from your terminal. This will download the Homebrew package manager on your machine.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2) FreeTDS: Run the following command from your terminal. This will install FreeTDS on your machine and is required for TinyTDS to work.

brew install FreeTDS

3) TinyTDS: Run the following command from your terminal. This will install TinyTDS on your machine.

gem install tiny_tds

Create a database, retrieve your connection string

The Ruby sample relies on the AdventureWorks sample database. If you do not already have AdventureWorks, you can see how to create it at the following topic: Create your first Azure SQL Database

##Using TinyTDS with Azure

It is recommend the following settings when using TinyTDS with Azure.

SET ANSI_NULLS ON
SET CURSOR_CLOSE_ON_COMMIT OFF
SET ANSI_NULL_DFLT_ON ON
SET IMPLICIT_TRANSACTIONS OFF
SET ANSI_PADDING ON
SET QUOTED_IDENTIFIER ON
SET ANSI_WARNINGS ON
SET CONCAT_NULL_YIELDS_NULL ON

This can be done by running the following code prior to executing queries:

result = client.execute("SET ANSI_NULLS ON")
result = client.execute("SET CURSOR_CLOSE_ON_COMMIT OFF")
result = client.execute("SET ANSI_NULL_DFLT_ON ON")
result = client.execute("SET IMPLICIT_TRANSACTIONS OFF")
result = client.execute("SET ANSI_PADDING ON")
result = client.execute("SET QUOTED_IDENTIFIER ON")
result = client.execute("SET ANSI_WARNINGS ON")
result = client.execute("SET CONCAT_NULL_YIELDS_NULL ON")