Browse Source

Finish getting ASP.NET to work with SQL Server

1. Add aspnet-sqlserver-raw and aspnet-sqlserver-entityframework tests.
2. Don't share DbParameter object between two SqlCommand objects because
   SqlCommand objects.
3. Get SQL Server working with the Entity Framework.
4. Tidy up T-SQL.
5. Fix typo in setup-sqlserver-bootstrap.ps1 with config path.
6. Complete SQL Server setup and configuration in setup-sqlserver.ps1.
Malcolm Evershed 12 years ago
parent
commit
13584af8c7

+ 22 - 2
aspnet/benchmark_config

@@ -38,6 +38,16 @@
       "port": 8080,
       "sort": 93
     },
+    "sqlserver-raw": {
+      "setup_file": "setup_iis",
+      "os": "nt",
+      "db_url": "/ado/sqlserver",
+      "query_url": "/ado/sqlserver?queries=",
+      "fortune_url": "/ado/sqlserver/fortunes",
+      "update_url": "/ado/sqlserver/update?queries=",
+      "port": 8080,
+      "sort": 94
+    },
     "mysql-entityframework": {
       "setup_file": "setup_iis",
       "os": "nt",
@@ -46,7 +56,7 @@
       "fortune_url": "/entityframework/mysql/fortunes",
       "update_url": "/entityframework/mysql/update?queries=",
       "port": 8080,
-      "sort": 94
+      "sort": 95
     },
     "postgresql-entityframework": {
       "setup_file": "setup_iis",
@@ -56,7 +66,17 @@
       "fortune_url": "/entityframework/postgresql/fortunes",
       "update_url": "/entityframework/postgresql/update?queries=",
       "port": 8080,
-      "sort": 95
+      "sort": 96
+    },
+    "sqlserver-entityframework": {
+      "setup_file": "setup_iis",
+      "os": "nt",
+      "db_url": "/entityframework/sqlserver",
+      "query_url": "/entityframework/sqlserver?queries=",
+      "fortune_url": "/entityframework/sqlserver/fortunes",
+      "update_url": "/entityframework/sqlserver/update?queries=",
+      "port": 8080,
+      "sort": 97
     },
     "mono": {
       "setup_file": "setup_nginx",

+ 5 - 1
aspnet/src/Controllers/AdoController.cs

@@ -143,12 +143,16 @@ namespace Benchmarks.AspNet.Controllers
                         if (world == null)
                             continue;
                         
+                        DbParameter idUpdateParameter = updateCommand.CreateParameter();
+                        idUpdateParameter.ParameterName = "@ID";
+                        idUpdateParameter.Value = randomID;
+
                         DbParameter numberParameter = updateCommand.CreateParameter();
                         numberParameter.ParameterName = "@Number";
                         numberParameter.Value = randomNumber;
 
                         updateCommand.Parameters.Clear();
-                        updateCommand.Parameters.Add(idParameter);
+                        updateCommand.Parameters.Add(idUpdateParameter);
                         updateCommand.Parameters.Add(numberParameter);
 
                         updateCommand.ExecuteNonQuery();

+ 1 - 1
aspnet/src/Web.config

@@ -25,7 +25,7 @@
     <providers>
       <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity, Version=6.7.2.0"/>
       <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql, Version=2.0.12.0"/>
-      <!-- TODO: Need for SQL Server -->
+      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
     </providers>
   </entityFramework>
   <appSettings>

+ 1 - 1
config/create-sqlserver-login-and-database.sql

@@ -14,7 +14,7 @@ CREATE LOGIN benchmarkdbuser WITH PASSWORD = 'B3nchmarkDBPass'
 GO
 
 IF EXISTS(SELECT * FROM SYS.DATABASES WHERE NAME='hello_world')
-DROP DATABASE hello_world
+    DROP DATABASE hello_world
 GO
 
 CREATE DATABASE hello_world

+ 1 - 1
setup-sqlserver-bootstrap.ps1

@@ -15,7 +15,7 @@ $create_sqlserver_url = $config_url + "/create-sqlserver.sql"
 $create_sqlserver_local = $config_local + "/create-sqlserver.sql"
 
 Write-Host "Creating directory: $config`n"
-New-Item -Path $config -Type Directory -Force | Out-Null
+New-Item -Path $config_local -Type Directory -Force | Out-Null
 
 Write-Host "Downloading setup files...`n"
 (New-Object System.Net.WebClient).DownloadFile($setup_sqlserver_url, $setup_sqlserver_local)

+ 68 - 20
setup-sqlserver.ps1

@@ -8,36 +8,84 @@ $basedir = "C:\FrameworkBenchmarks"
 $workdir = "$basedir\installs"
 New-Item -Path $workdir -Type directory -Force | Out-Null
 
-Write-Host "Downloading SQL Server (several GBs)...`n"
+If (-Not (Get-Service | ? Name -Eq "MSSQLSERVER")) {
 
-# URLs from http://www.microsoft.com/en-us/download/details.aspx?id=35575
+  Write-Host "Could not find default SQL Server instance, MSSQLSERVER."
+  Write-Host "Downloading SQL Server (several GBs)..."
 
-$sqlserver_exe_url = "http://download.microsoft.com/download/3/B/D/3BD9DD65-D3E3-43C3-BB50-0ED850A82AD5/SQLServer2012SP1-FullSlipstream-x64-ENU.exe"
-$sqlserver_exe_local = "$workdir\SQLServer2012SP1-FullSlipstream-x64-ENU.exe"
-(New-Object System.Net.WebClient).DownloadFile($sqlserver_exe_url, $sqlserver_exe_local)
+  # URLs from http://www.microsoft.com/en-us/download/details.aspx?id=35575
 
-$sqlserver_box_url = "http://download.microsoft.com/download/3/B/D/3BD9DD65-D3E3-43C3-BB50-0ED850A82AD5/SQLServer2012SP1-FullSlipstream-x64-ENU.box"
-$sqlserver_box_local = "$workdir\SQLServer2012SP1-FullSlipstream-x64-ENU.box"
-(New-Object System.Net.WebClient).DownloadFile($sqlserver_box_url, $sqlserver_box_local)
+  $sqlserver_exe_url = "http://download.microsoft.com/download/3/B/D/3BD9DD65-D3E3-43C3-BB50-0ED850A82AD5/SQLServer2012SP1-FullSlipstream-x64-ENU.exe"
+  $sqlserver_exe_local = "$workdir\SQLServer2012SP1-FullSlipstream-x64-ENU.exe"
+  (New-Object System.Net.WebClient).DownloadFile($sqlserver_exe_url, $sqlserver_exe_local)
 
-Write-Host "Installing SQL Server...`n"
+  $sqlserver_box_url = "http://download.microsoft.com/download/3/B/D/3BD9DD65-D3E3-43C3-BB50-0ED850A82AD5/SQLServer2012SP1-FullSlipstream-x64-ENU.box"
+  $sqlserver_box_local = "$workdir\SQLServer2012SP1-FullSlipstream-x64-ENU.box"
+  (New-Object System.Net.WebClient).DownloadFile($sqlserver_box_url, $sqlserver_box_local)
 
-# Install only the SQL Server database engine.
-# Use a default instance name.
-# Make %COMPUTERNAME%\Administrators have administrative rights.
-# Allow Windows Authentication or old-style SQL authentication.
-# The password of the sa account is specified.
-# SQL Server will be listening on TCP port 1433.
-#
-Start-Process "$sqlserver_exe_local" "/q /action=install /features=SQLEngine /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=Administrators /securitymode=SQL /sapwd=S3cr3tS3cr3t /TCPENABLED=1 /IACCEPTSQLSERVERLICENSETERMS" -Wait
+  Write-Host "Installing SQL Server..."
+
+  # Install only the SQL Server database engine.
+  # Use a default instance name.
+  # Make %COMPUTERNAME%\Administrators have administrative rights.
+  
+  # The following is not used because this is done in PowerShell below.
+  #   /securitymode=SQL /sapwd=S3cr3tS3cr3t /TCPENABLED=1
+  #   Allow Windows Authentication or old-style SQL authentication.
+  #   The password of the sa account is specified.
+  #   SQL Server will be listening on TCP port 1433.
+  #
+  Start-Process "$sqlserver_exe_local" "/q /action=install /features=SQLEngine /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=Administrators /IACCEPTSQLSERVERLICENSETERMS" -Wait
+}
 
-Write-Host "Configuring firewall...`n"
-New-NetFirewallRule -DisplayName "SQL 1433" -Action Allow -Direction Inbound -LocalPort 1433 -Protocol TCP | Out-Null
+# In case we just installed SQL Server and the environment variables haven't been refreshed, manually
+# refresh PSModulePath so that Import-Module sqlps will work.
 
-Write-Host "Creating SQL Server login and populated database...`n"
+$env:PSModulePath = [Environment]::GetEnvironmentVariable("PSModulePath", [System.EnvironmentVariableTarget]::Machine)
 
 Import-Module sqlps
 
+Write-Host "Setting SQL Server to start on boot..."
+
+Set-Service MSSQLSERVER -StartupType Automatic
+
+Write-Host "Ensuring that SQL Server is started..."
+
+Start-Service MSSQLSERVER
+
+Write-Host "Enabling SQL authentication..."
+
+# Enable SQL authentication
+$s = New-Object ('Microsoft.SqlServer.Management.Smo.Server')
+$s.Settings.LoginMode = [Microsoft.SqlServer.Management.SMO.ServerLoginMode]::Mixed
+$s.Alter()
+
+Write-Host "Configuring SQL Server to listen on TCP (default port 1433)..."
+
+# Enable the TCP protocol on the default instance.
+$wmi = New-Object ('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer')
+$uri = "ManagedComputer[@Name='" + (Get-Content env:computername) + "']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Tcp']"
+$Tcp = $wmi.GetSmoObject($uri)
+$Tcp.IsEnabled = $true
+$Tcp.Alter()
+
+Write-Host "Restarting SQL Server..."
+
+Restart-Service -Name MSSQLSERVER
+
+If (-Not (Get-NetFirewallPortFilter | ? LocalPort -Eq "1433")) {
+  Write-Host "Opening port 1433 in firewall..."
+  New-NetFirewallRule -DisplayName "SQL 1433" -Action Allow -Direction Inbound -LocalPort 1433 -Protocol TCP | Out-Null
+} else {
+  Write-Host "Port 1433 is already configured in firewall."
+}
+
+Write-Host "Creating SQL Server login and populated database..."
+
+# Connect with Windows Authentication, assuming that we have access.
 Invoke-Sqlcmd -InputFile "$basedir\config\create-sqlserver-login-and-database.sql" -OutputSqlErrors $True
 
+# Now that benchmarkdbuser has been created, we can connect with those credentials.
 Invoke-Sqlcmd -Username benchmarkdbuser -Password B3nchmarkDBPass -Database hello_world -InputFile "$basedir\config\create-sqlserver.sql" -OutputSqlErrors $True
+
+Write-Host "Done."