Skip to content

Commit d364e87

Browse files
authored
Merge pull request microsoft#2 from JocaPC/json
Minor fixes
2 parents 29cdb0d + 0e46c20 commit d364e87

File tree

8 files changed

+109
-29
lines changed

8 files changed

+109
-29
lines changed

samples/features/json/todo-app/dotnet-rest-api/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ASP.NET Core REST Web API that uses SQL/JSON functionalites
1+
# ASP.NET Core REST Web API that uses SQL/JSON functionalities
22

33
This project contains an example implementation of ASP.NET Core REST API with CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database.
44

@@ -61,7 +61,7 @@ Service uses built-in JSON functionalities that are available in SQL Server 2016
6161
<a name=disclaimers></a>
6262

6363
## Disclaimers
64-
The code included in this sample is not intended demonstrate some general guidances and arhitectural patterns for web development. It contains minimal code required to create REST API, and it does not use some patterns such as Repository. Sample uses built-in ASP.NET Core Dependency Injection mechanism; however, this is not prerequisite.
64+
The code included in this sample is not intended demonstrate some general guidance and architectural patterns for web development. It contains minimal code required to create REST API, and it does not use some patterns such as Repository. Sample uses built-in ASP.NET Core Dependency Injection mechanism; however, this is not prerequisite.
6565
You can easily modify this code to fit the architecture of your application.
6666

6767
<a name=related-links></a>
@@ -70,8 +70,11 @@ You can easily modify this code to fit the architecture of your application.
7070

7171
For more information, see this [article](http://www.codeproject.com/Articles/1106622/Building-Web-API-REST-services-on-Azure-SQL-Databa).
7272

73+
## Code of Conduct
74+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
75+
7376
## License
7477
These samples and templates are all licensed under the MIT license. See the license.txt file in the root.
7578

7679
## Questions
77-
Email questions to: sqlserversamples@microsoft.com.
80+
Email questions to: [sqlserversamples@microsoft.com](mailto: sqlserversamples@microsoft.com).
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node_modules/*
2-
bin/*
2+
bin/*.dll
33
obj/*
44
*.sln
55
*.log

samples/features/json/todo-app/nodejs-express4-rest-api/README.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# NodeJS Express4 REST API that uses SQL/JSON functionalites
1+
# NodeJS Express4 REST API that uses SQL/JSON functionalities
22

3-
This project contains an example implementation of NodeJS REST API with CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database.
3+
This project contains an example implementation of NodeJS REST API with CRUD operations on a simple Todo table. You can learn how to build REST API on the existing database schema using NodeJS, Express4, and new JSON functionalities that are available in SQL Server 2016 (or higher) and Azure SQL Database.
44

55
### Contents
66

@@ -39,31 +39,40 @@ To run this sample, you need the following prerequisites.
3939

4040
## Run this sample
4141

42-
1. Navigate to the folder where you have downloaded sample and run **npm install** in command window. This command will install necessary npm packages defined in project.json.
42+
1. Navigate to the folder where you have downloaded sample and run **npm install** in command window, or run setup.bat if you are on Windows operating system. This command will install necessary npm packages defined in project.json.
4343

44-
2. From SQL Server Management Studio or Sql Server Data Tools connect to your SQL Server 2016 or Azure SQL database and execute setup.sql script that will create and populate Todo table in the database.
44+
2. From SQL Server Management Studio or SQL Server Data Tools connect to your SQL Server 2016 or Azure SQL database and execute setup.sql script that will create and populate Todo table in the database.
4545

4646
3. From Visual Studio, open the **TodoApp.xproj** file from the root directory,
4747

48-
4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database, and build solution using Ctrl+Shift+B, right-click on project + Build, or Build/Build Solution from menu.
48+
4. Locate db.js file in the project, change database connection info in createConnection() method to reference your database. the following tokens should be replaced:
49+
4.1. SERVERNAME - name of the database server.
50+
4.2. DATABASE - Name of database where Todo table is stored.
51+
4.3. USERNAME - SQL Server login that can access table data and execute stored procedures.
52+
4.4. PASSWORD - Password associated to SQL Server login.
4953

50-
5. Run sample app using F5 or Ctrl+F5,
51-
4.1. Open /api/Todo Url to get all Todo items as a JSON array,
52-
4.2. Open /api/Todo/1 Url to get details about a single Todo item with id 1,
53-
4.3. Send POST, PUT, PATCH, or DELETE Http requests to update content of Todo table.
54+
5. Build project using Ctrl+Shift+B, right-click on project + Build, or Build/Build Solution from menu.
55+
56+
6. Run sample app using F5 or Ctrl+F5. /todo Url will be opened with a list of all Todo items as a JSON array,
57+
6.1. Open /api/Todo/1 Url to get details about a single Todo item with id 1,
58+
6.2. Send POST, PUT, or DELETE Http requests to update content of Todo table.
5459

5560
<a name=sample-details></a>
5661

5762
## Sample details
5863

5964
This sample application shows how to create simple REST API service that performs CRUD operations on a simple Todo table.
6065
NodeJS REST API is used to implement REST Service in the example.
61-
Service uses built-in JSON functionalities that are available in SQL Server 2016 and Azure SQL Database.
66+
1. app.js file that contains startup code.
67+
2. db.js file that contains functions that wrap Tedious library
68+
3. todo.js file that contains action that will be called on GET, POST, PUT, and DELETE Http requests.
69+
70+
Service uses Tedious library for data access and built-in JSON functionalities that are available in SQL Server 2016 and Azure SQL Database.
6271

6372
<a name=disclaimers></a>
6473

6574
## Disclaimers
66-
The code included in this sample is not intended demonstrate some general guidances and arhitectural patterns for web development.
75+
The code included in this sample is not intended demonstrate some general guidance and architectural patterns for web development.
6776
It contains minimal code required to create REST API.
6877
You can easily modify this code to fit the architecture of your application.
6978

@@ -80,4 +89,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
8089
These samples and templates are all licensed under the MIT license. See the license.txt file in the root.
8190

8291
## Questions
83-
Email questions to: sqlserversamples@microsoft.com.
92+
Email questions to: [sqlserversamples@microsoft.com](mailto: sqlserversamples@microsoft.com).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
var debug = require('debug')('nodejs_express4_rest_api');
3+
var app = require('../app');
4+
5+
app.set('port', process.env.PORT || 3000);
6+
7+
var server = app.listen(app.get('port'), function() {
8+
debug('Express server listening on port ' + server.address().port);
9+
});

samples/features/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ Master Data Services (MDS) is the SQL Server solution for master data management
1111
[R Services](features/r-services)
1212

1313
SQL Server R Services brings R processing close to the data, allowing more scalable and more efficient predictive analytics.
14+
15+
[JSON Support](features/json)
16+
17+
Built-in JSON functions enable you to easily parse and query JSON data stored in database, transform relational data to JSON text, and vice versa.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# mssql server 2014 express image listening on static port 1433
2-
#
3-
# Note: This dockerfile is based on Buc Rogers' work here:
2+
#
3+
# Note: This dockerfile is based on Buc Rogers' work here:
44
# https://github.com/brogersyh/Dockerfiles-for-windows/tree/master/sqlexpress
55
#
66
# .NET 3.5 required for SQL Server
@@ -12,19 +12,20 @@ MAINTAINER Perry Skountrianos
1212
# set environment variables
1313
ENV sql_express_download_url "https://download.microsoft.com/download/1/5/6/156992E6-F7C7-4E55-833D-249BD2348138/ENU/x64/SQLEXPR_x64_ENU.exe"
1414
ENV sa_password _
15+
ENV attach_dbs "[]"
1516

1617
# make install files accessible
1718
COPY . /
1819
WORKDIR /
1920

20-
# download and install Microsoft SQL 2014 Express Edition in one step
21+
# download and install Microsoft SQL 2014 Express Edition in one step
2122
RUN powershell -Command (New-Object System.Net.WebClient).DownloadFile('%sql_express_download_url%', 'sqlexpress.exe') && /sqlexpress.exe /qs /x:setup && /setup/setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT="NT AUTHORITY\System" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS && del /F /Q sqlexpress.exe && rd /q /s setup
2223

2324
RUN powershell -Command \
2425
set-strictmode -version latest ; \
2526
stop-service MSSQL`$SQLEXPRESS ; \
2627
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \
2728
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \
28-
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\' -name LoginMode -value 2 ;
29+
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql12.SQLEXPRESS\mssqlserver\' -name LoginMode -value 2 ;
2930

30-
CMD powershell ./start %sa_password%
31+
CMD powershell ./start -sa_password %sa_password% -attach_dbs \"%attach_dbs%\" -Verbose

samples/manage/windows-containers/mssql-server-2014-express-windows/readme.md

+33-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Note: This dockerfile is based on Buc Rogers' work that can be found [here] (htt
1717
## About this sample
1818

1919
1. **Applies to:** SQL Server 2014 Express, Windows Server Technical Preview 4 or later
20-
5. **Authors:** Perry Skountrianos [perrysk-msft]
20+
5. **Authors:** Perry Skountrianos [perrysk-msft], Max Knor [knom]
2121

2222
<a name=before-you-begin></a>
2323

@@ -27,16 +27,44 @@ To run this sample, you need the following prerequisites.
2727

2828
**Software prerequisites:**
2929

30-
You can run the container with the following command. Note the you'll need Windows Server Core TP5 v10.0.14300.1000.
31-
docker run -p 1433:1433 --env sa_password=<YOUR SA PASSWORD> microsoft/mssql-server-2014-express-windows
30+
You can run the container with the following command.
31+
(Note the you'll need Windows Server Core TP5 v10.0.14300.1000.)
32+
33+
````
34+
docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env sa_password=<YOUR SA PASSWORD> --env attach_dbs="<DB-JSON-CONFIG>" -v microsoft/mssql-server-2014-express-windows
35+
````
36+
37+
- **-p HostPort:containerPort** is for port-mapping a container network port to a host port.
38+
- **-v HostPath:containerPath** is for mounting a folder from the host inside the container.
39+
40+
This can be used for saving database outside of the container.
3241

3342
<a name=run-this-sample></a>
3443

3544
## Run this sample
3645

37-
The image provides one environment variable to set the sa password: </br>
46+
The image provides two environment variables to optionally set: </br>
3847
- sa_password: Sets the sa password and enables the sa login
39-
48+
- attach_dbs: The configuration for attaching custom DBs (.mdf, .ldf files).
49+
50+
This should be a JSON string, formed like the following (note the SINGLE quotes and everything in one line):
51+
```
52+
[{'dbName':'MaxDb','dbFiles':['C:\\temp\\maxtest.mdf','C:\\temp\\maxtest_log.
53+
ldf']},{'dbName':'PerryDb','dbFiles':['C:\\temp\\perrytest.mdf','C:\\temp\\perrytest_log.
54+
ldf']}]
55+
```
56+
There can be zero to many databases in the array.
57+
- dbName: The name of the database
58+
- dbFiles: An array of absolute paths to the .MDF and .LDF files.
59+
60+
Can be one or many, note that the path has double backslashes for escaping!
61+
62+
This example shows all parameters in action:
63+
```
64+
docker run -p 1433:1433 -v C:/temp/:C:/temp/ --env attach_dbs="[{'dbName':'MaxTest','dbFiles':['C:\\temp\\maxtest.mdf','C:\\temp\\maxtest_log.
65+
ldf']}]" microsoft/mssql-server-2014-express-windows
66+
```
67+
4068
<a name=sample-details></a>
4169

4270
## Sample details
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
1-
# The script sets the sa password and start the SQl Service
1+
# The script sets the sa password and start the SQL Service
2+
# Also it attaches additional database from the disk
3+
# The format for attach_dbs
24

35
param(
46
[Parameter(Mandatory=$false)]
5-
[string]$sa_password
7+
[string]$sa_password,
8+
9+
[Parameter(Mandatory=$false)]
10+
[string]$attach_dbs
611
)
712

813
# start the service
14+
Write-Verbose "Starting SQL Server"
915
start-service MSSQL`$SQLEXPRESS
1016

11-
1217
if($sa_password -ne "_"){
18+
Write-Verbose "Changing SA login credentials"
1319
$sqlcmd = "ALTER LOGIN sa with password=" +"'" + $sa_password + "'" + ";ALTER LOGIN sa ENABLE;"
1420
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
1521
}
1622

23+
$attach_dbs = $attach_dbs | ConvertFrom-Json
24+
25+
if ($null -ne $attach_dbs){
26+
Write-Verbose "Attaching database(s)"
27+
Foreach($db in $attach_dbs)
28+
{
29+
$files = @();
30+
Foreach($file in $db.dbFiles)
31+
{
32+
$files += "(FILENAME = 'N$($file)')";
33+
}
34+
35+
$files = $files -join ","
36+
$sqlcmd = "sp_detach_db $($db.dbName);GO;CREATE DATABASE $($db.dbName) ON $($files) FOR ATTACH ;GO;"
37+
38+
Write-Host Invoke-Sqlcmd -Query $($sqlcmd) -ServerInstance ".\SQLEXPRESS"
39+
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
40+
}
41+
}
42+
1743
while ($true) { Start-Sleep -Seconds 3600 }

0 commit comments

Comments
 (0)