├── .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 | MSSQL Comments! 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 29 | 30 | 31 |
32 |
33 |

MSSQL Comments

34 |

Use this app as a way to quickly test the connection with the Microsoft SQL Server instance running inside the Vagrant VM.

35 |
36 |
37 |
38 |
39 |
40 | 41 | 42 |
43 |
44 | 45 | 46 |
47 | 48 |
49 |
50 |
51 | <% if @comments.any? %> 52 |

Comments

53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | <% @comments.each do |comment| %> 62 | 63 | 64 | 65 | 66 | <% end %> 67 | 68 | <% else %> 69 |

No comments found!

70 | <% end %> 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vagrant-mssql-express 2 | 3 | A Windows Server 2008 R2 VM with SQL Server Express 2008 R2 SP2 powered by Vagrant. 4 | 5 | ## :warning: Heads up! :warning: 6 | 7 | This was just an experiment on how to set things up for a project I worked on the past, I'm not planning to keep this project up to date with latest Vagrant / SQL Server updates or making additional improvements to it. 8 | 9 | ## Requirements 10 | 11 | * Vagrant 1.6+ (tested on 1.6.3) 12 | * VirtualBox 4.3+ (tested on 4.3.16 on an Ubuntu host) 13 | * Around `12GB` of disk space (`3GB` for base box + `~9GB` for the VM) 14 | 15 | ## Base box information 16 | 17 | * Configured with 2 CPU and 2 GB memory by default. 18 | * No updates or services packs applied 19 | * The box is not activated. It has been created for testing and evaluation 20 | purposes only. Use of this machine for greater than 30 days will require a 21 | full license either via MSDN or your local Microsoft Reseller. 22 | * The box has been created with [packer.io](http://www.packer.io/) using the 23 | templates made available [here](https://github.com/opentable/packer-images). 24 | 25 | More information can be found on the [box page at Vagrant Cloud](https://vagrantcloud.com/opentable/boxes/win-2008r2-standard-amd64-nocm). 26 | 27 | ## Usage 28 | 29 | ```sh 30 | git clone https://github.com/fgrehm/vagrant-mssql-express.git 31 | cd vagrant-mssql-express 32 | # Download SQL Server with Tools installer 33 | wget http://download.microsoft.com/download/0/4/B/04BE03CD-EAF3-4797-9D8D-2E08E316C998/SQLEXPRWT_x64_ENU.exe 34 | vagrant up 35 | # Get a coffee as it will take a while for it to finish provisioning 36 | ``` 37 | 38 | Then test the connection with the SQL Server using `telnet 192.168.50.4 1433` 39 | 40 | 41 | ### Connecting to the SQL Server instance that runs inside the VM 42 | 43 | * IP / Host: `192.168.50.4` 44 | * Username: `sa` 45 | * Password: `#SAPassword!` 46 | 47 | If you are using Rails, apart from installing [tiny_tds](https://github.com/rails-sqlserver/tiny_tds) 48 | dependencies with `brew install freetds` / `apt-get install freetds-*` and 49 | the [activerecord-sqlserver-adapter gem](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter), 50 | this is what you'll have on your `database.yml`: 51 | 52 | ```yaml 53 | development: 54 | adapter: sqlserver 55 | database: 56 | host: 192.168.50.4 57 | username: sa 58 | password: '#SAPassword!' 59 | ``` 60 | 61 | _More information on https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Using-TinyTDS_ 62 | 63 | An example [Sinatra](http://www.sinatrarb.com) app can be found on [sinatra-app](sinatra-app). 64 | 65 | ### Connecting to the VM using [Remote Desktop](https://en.wikipedia.org/wiki/Remote_Desktop_Protocol) connections 66 | 67 | If you need to perform administrative tasks like importing a DB dump or creating 68 | new databases, you can use the [`vagrant rdp` command](http://docs.vagrantup.com/v2/cli/rdp.html) 69 | and log in with the `vagrant` user and password. 70 | 71 | For the `vagrant rdp` command to work on Ubuntu, you'll need to `apt-get install rdesktop` 72 | first. On Macs, you will need [Microsoft Remote Desktop](https://itunes.apple.com/en/app/microsoft-remote-desktop/id715768417) from the Mac App Store. 73 | 74 | ## More information 75 | 76 | If you want to know more about how the provisioning process work, check out 77 | [this blog post](http://helabs.com.br/blog/2014/09/19/mssql-on-vagrant/) 78 | 79 | ## Sponsor 80 | 81 | This project was made possible thanks to [HE:labs](http://helabs.com.br/en) 82 | 83 | ## Resources 84 | 85 | Here's some links I collected along the way while building this: 86 | 87 | * http://msdn.microsoft.com/en-us/library/ms144259%28v=SQL.100%29.aspx 88 | * http://technet.microsoft.com/en-us/library/ee176858.aspx 89 | * http://iqbalnaved.wordpress.com/2013/09/28/configuration-for-connecting-to-mssql-server-2008-on-virtualbox-guestos-from-ubuntu-12-04-hostos-using-pyodbc-3-0-8/ 90 | * http://technet.microsoft.com/en-us/library/dd206997(v=sql.105).aspx 91 | * http://sirsql.net/blog/2011/6/21/set-the-sql-tcpip-port-with-powershell.html 92 | --------------------------------------------------------------------------------
NameMessage
<%= comment.name %><%= comment.message.gsub("\n", "
") %>