├── .gitignore ├── SPONSORS ├── sinatra-app ├── Rakefile ├── Gemfile ├── database.yml ├── db │ ├── migrate │ │ └── 20140913010102_create_comments.rb │ └── schema.rb ├── app.rb ├── Gemfile.lock └── views │ └── index.erb ├── scripts ├── install-dot-net.ps1 ├── enable-rdp.ps1 ├── install-sql-server.cmd └── configure-sql-port.ps1 ├── Vagrantfile ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | -------------------------------------------------------------------------------- /SPONSORS: -------------------------------------------------------------------------------- 1 | HE:labs http://helabs.com.br/en 2 | -------------------------------------------------------------------------------- /sinatra-app/Rakefile: -------------------------------------------------------------------------------- 1 | # Rakefile 2 | require "sinatra/activerecord/rake" 3 | require "./app" 4 | -------------------------------------------------------------------------------- /sinatra-app/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem 'sinatra-activerecord' 4 | gem 'tiny_tds' 5 | gem 'activerecord-sqlserver-adapter' 6 | gem 'rake' 7 | -------------------------------------------------------------------------------- /sinatra-app/database.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: sqlserver 3 | database: test-app 4 | host: 192.168.50.4 5 | username: sa 6 | password: '#SAPassword!' 7 | pool: 15 8 | timeout: 5000 9 | -------------------------------------------------------------------------------- /scripts/install-dot-net.ps1: -------------------------------------------------------------------------------- 1 | # http://stackoverflow.com/a/9949105 2 | $ErrorActionPreference = "Stop" 3 | 4 | import-module servermanager 5 | echo "Installing .NET Framework" 6 | add-windowsfeature as-net-framework 7 | -------------------------------------------------------------------------------- /sinatra-app/db/migrate/20140913010102_create_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateComments < ActiveRecord::Migration 2 | def change 3 | create_table :comments do |t| 4 | t.string :name 5 | t.text :message 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /scripts/enable-rdp.ps1: -------------------------------------------------------------------------------- 1 | # http://stackoverflow.com/a/9949105 2 | $ErrorActionPreference = "Stop" 3 | 4 | # http://networkerslog.blogspot.com.br/2013/09/how-to-enable-remote-desktop-remotely.html 5 | set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0 6 | -------------------------------------------------------------------------------- /sinatra-app/app.rb: -------------------------------------------------------------------------------- 1 | require 'sinatra' 2 | require "sinatra/activerecord" 3 | 4 | set :database_file, "./database.yml" 5 | 6 | class Comment < ActiveRecord::Base 7 | end 8 | 9 | get '/' do 10 | @comments = Comment.all 11 | erb :index 12 | end 13 | 14 | post '/' do 15 | Comment.create!( 16 | name: params[:name], 17 | message: params[:message] 18 | ) 19 | redirect '/' 20 | end 21 | -------------------------------------------------------------------------------- /scripts/install-sql-server.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Installing SQL Server 2008 Express R2, it will take a while... 4 | C:\vagrant\SQLEXPRWT_x64_ENU.exe /Q /Action=install /INDICATEPROGRESS /INSTANCENAME="SQLEXPRESS" /INSTANCEID="SQLExpress" /IAcceptSQLServerLicenseTerms /FEATURES=SQL,Tools /TCPENABLED=1 /SECURITYMODE="SQL" /SAPWD="#SAPassword!" 5 | echo Done! 6 | 7 | echo Disabling firewall 8 | netsh advfirewall set allprofiles state off 9 | -------------------------------------------------------------------------------- /sinatra-app/db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended that you check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(version: 20140913010102) do 15 | 16 | create_table "comments", force: true do |t| 17 | t.string "name" 18 | t.text "message" 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox' 8 | 9 | if ! File.exists?('./SQLEXPRWT_x64_ENU.exe') 10 | puts 'SQL Server installer could not be found!' 11 | puts "Please run:\n wget http://download.microsoft.com/download/0/4/B/04BE03CD-EAF3-4797-9D8D-2E08E316C998/SQLEXPRWT_x64_ENU.exe" 12 | exit 1 13 | end 14 | 15 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 16 | config.vm.box = "opentable/win-2008r2-standard-amd64-nocm" 17 | config.vm.network "private_network", ip: "192.168.50.4" 18 | config.vm.network :forwarded_port, guest: 3389, host: 3389 19 | 20 | config.vm.provision :shell, path: "scripts/install-dot-net.ps1" 21 | config.vm.provision :shell, path: "scripts/install-sql-server.cmd" 22 | config.vm.provision :shell, path: "scripts/configure-sql-port.ps1" 23 | config.vm.provision :shell, path: "scripts/enable-rdp.ps1" 24 | end 25 | -------------------------------------------------------------------------------- /scripts/configure-sql-port.ps1: -------------------------------------------------------------------------------- 1 | # http://stackoverflow.com/a/9949105 2 | $ErrorActionPreference = "Stop" 3 | 4 | echo "Configuring TCP port" 5 | 6 | # http://technet.microsoft.com/en-us/library/dd206997(v=sql.105).aspx 7 | # Load assemblies 8 | [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") 9 | [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") 10 | 11 | # http://www.dbi-services.com/index.php/blog/entry/sql-server-2012-configuring-your-tcp-port-via-powershell 12 | # Set the port 13 | $smo = 'Microsoft.SqlServer.Management.Smo.' 14 | $wmi = new-object ($smo + 'Wmi.ManagedComputer') 15 | $uri = "ManagedComputer[@Name='WIN-2008R2-STD']/ ServerInstance[@Name='SQLEXPRESS']/ServerProtocol[@Name='Tcp']" 16 | $Tcp = $wmi.GetSmoObject($uri) 17 | $wmi.GetSmoObject($uri + "/IPAddress[@Name='IPAll']").IPAddressProperties[1].Value="1433" 18 | $Tcp.alter() 19 | 20 | echo "DONE!" 21 | 22 | echo "Restarting service..." 23 | # Restart service so that configurations are applied 24 | restart-service -f "SQL Server (SQLEXPRESS)" 25 | echo "DONE!" 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Fabio Rehm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /sinatra-app/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | activemodel (4.1.5) 5 | activesupport (= 4.1.5) 6 | builder (~> 3.1) 7 | activerecord (4.1.5) 8 | activemodel (= 4.1.5) 9 | activesupport (= 4.1.5) 10 | arel (~> 5.0.0) 11 | activerecord-sqlserver-adapter (4.1.0) 12 | activerecord (~> 4.1.0) 13 | arel 14 | activesupport (4.1.5) 15 | i18n (~> 0.6, >= 0.6.9) 16 | json (~> 1.7, >= 1.7.7) 17 | minitest (~> 5.1) 18 | thread_safe (~> 0.1) 19 | tzinfo (~> 1.1) 20 | arel (5.0.1.20140414130214) 21 | builder (3.2.2) 22 | i18n (0.6.11) 23 | json (1.8.1) 24 | minitest (5.4.1) 25 | rack (1.5.2) 26 | rack-protection (1.5.3) 27 | rack 28 | rake (10.3.2) 29 | sinatra (1.4.5) 30 | rack (~> 1.4) 31 | rack-protection (~> 1.4) 32 | tilt (~> 1.3, >= 1.3.4) 33 | sinatra-activerecord (2.0.2) 34 | activerecord (>= 3.2) 35 | sinatra (~> 1.0) 36 | thread_safe (0.3.4) 37 | tilt (1.4.1) 38 | tiny_tds (0.6.2) 39 | tzinfo (1.2.2) 40 | thread_safe (~> 0.1) 41 | 42 | PLATFORMS 43 | ruby 44 | 45 | DEPENDENCIES 46 | activerecord-sqlserver-adapter 47 | rake 48 | sinatra-activerecord 49 | tiny_tds 50 | -------------------------------------------------------------------------------- /sinatra-app/views/index.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |Use this app as a way to quickly test the connection with the Microsoft SQL Server instance running inside the Vagrant VM.
35 || Name | 57 |Message | 58 |
|---|---|
| <%= comment.name %> | 64 |<%= comment.message.gsub("\n", " ") %> |
65 |