All Projects → sanagama → mssql-restapi

sanagama / mssql-restapi

Licence: MIT license
A simple REST API for SQL Server, Azure SQL DB and Azure SQL DW using SMO on .NET Core 2.0

Programming Languages

C#
18002 projects
shell
77523 projects

Projects that are alternatives of or similar to mssql-restapi

MinimalApi
ASP.NET Core 7.0 - Minimal API Example - Todo API implementation using ASP.NET Core Minimal API, Entity Framework Core, Token authentication, Versioning, Unit Testing, Integration Testing and Open API.
Stars: ✭ 156 (+372.73%)
Mutual labels:  sql-server, aspnetcore, aspnet-core
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+163.64%)
Mutual labels:  aspnetcore, netcore, aspnet-core
awesome-dotnet-async
A curated list of awesome articles and resources to learning and practicing about async, threading, and channels in .Net platform. 😉
Stars: ✭ 84 (+154.55%)
Mutual labels:  aspnetcore, netcore, aspnet-core
Formhelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)
Stars: ✭ 155 (+369.7%)
Mutual labels:  aspnetcore, netcore, aspnet-core
Restairline
DDD+CQRS+EventSourcing+Hypermedia API+ASP.NET Core 3.1+Masstransit+terraform+docker+k8s
Stars: ✭ 243 (+636.36%)
Mutual labels:  aspnetcore, aspnet-core, restful-api
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (+390.91%)
Mutual labels:  aspnetcore, netcore, aspnet-core
Bing.netcore
Bing是基于 .net core 2.0 的框架,旨在提升团队的开发输出能力,由常用公共操作类(工具类、帮助类)、分层架构基类,第三方组件封装,第三方业务接口封装等组成。
Stars: ✭ 758 (+2196.97%)
Mutual labels:  aspnetcore, netcore, aspnet-core
OrdersManagementSystem
Project demonstrates usage of Prism composition library, Material design library, SQL Server, Entity Framework in WPF application
Stars: ✭ 29 (-12.12%)
Mutual labels:  sql-server, aspnetcore, sqlserver
fullcalendar-aspnet-core
Implementation of FullCalendar in ASP.NET Core
Stars: ✭ 30 (-9.09%)
Mutual labels:  sql-server, netcore, aspnet-core
pypyodbc
pypyodbc is a pure Python cross platform ODBC interface module (pyodbc compatible as of 2017)
Stars: ✭ 39 (+18.18%)
Mutual labels:  sql-server, sqlserver
tsql-scripts
Transact-SQL scripts and gists
Stars: ✭ 35 (+6.06%)
Mutual labels:  sql-server, sqlserver
comcms
COMCMS_Core 版本
Stars: ✭ 32 (-3.03%)
Mutual labels:  aspnetcore, netcore
fullstack-jobs
Real(ish) demo using Angular with ASP.NET Core GraphQL and IdentityServer.
Stars: ✭ 84 (+154.55%)
Mutual labels:  sql-server, aspnet-core
TheLastTime
C# .NET 5 Blazor WebAssembly Progressive Web Application that tracks when was the last time you did something
Stars: ✭ 23 (-30.3%)
Mutual labels:  aspnetcore, aspnet-core
high-performance-aspnet-core-workshop
Sample application used in the High-Performance ASP.NET Core Workshop
Stars: ✭ 29 (-12.12%)
Mutual labels:  aspnetcore, aspnet-core
grandnode2
Free, Open source, Fast, Headless, Multi-tenant eCommerce platform built with .NET Core, MongoDB, AWS DocumentDB, Azure CosmosDB, LiteDB, Vue.js.
Stars: ✭ 626 (+1796.97%)
Mutual labels:  aspnetcore, netcore
gothic
🦇 Gothic is a user registration and authentication SWT/JWT microservice. It supports REST, gRPC, and gRPC Web API, reCAPTCHA & a variety of DBs with Gorm.
Stars: ✭ 65 (+96.97%)
Mutual labels:  sqlserver, restful-api
AspNetCore.TestHost.WindowsAuth
Implements Windows authentication for ASP.NET Core TestServer-based integration test projects.
Stars: ✭ 21 (-36.36%)
Mutual labels:  aspnetcore, aspnet-core
run-aspnetcore-basics retired
One Solution - One Project for web application development with Asp.Net Core & EF.Core. Only one web application project which used aspnetcore components; razor pages, middlewares, dependency injection, configuration, logging. To create websites with minimum implementation of asp.net core based on HTML5, CSS, and JavaScript. You can use this boi…
Stars: ✭ 15 (-54.55%)
Mutual labels:  aspnetcore, aspnet-core
DNZ.MvcComponents
A set of useful UI-Components (HtmlHelper) for ASP.NET Core MVC based-on Popular JavaScript Plugins (Experimental project).
Stars: ✭ 25 (-24.24%)
Mutual labels:  aspnetcore, aspnet-core

What's here?

This is a prototype of a simple ASP.NET Core 2.0 REST API web app that uses SQL Server Management Objects (SMO) under the covers to provide a RESTful interface for SQL Server running anywhere.

You can run this REST API web app on Linux, macOS, Windows or Docker and optionally use environment variables to connect to a local or remote SQL Server instance, Azure SQL Database and Azure SQL Data Warehouse.

For fun, I've added GET REST API end-points to:

  • navigate Server -> Databases -> Tables -> Columns
  • generate CREATE DATABASE and CREATE TABLE T-SQL scripts
  • view data in tables

Thanks to SMO, the REST API always returns up-to-date information when any schema or data changes occur in the database while the web app is running.

Currently, only the the GET verb is supported. In the future, I plan to add support for:

  • other REST verbs (PUT, POST, UPDATE and DELETE)
  • more database objects such as Views, Stored Procedures, Schemas and UDTs
  • pagination for tables with a large number of rows

Try it out!

The instructions below are for a MacBook. Modify as needed if you're using Linux or Windows.

Step 1: Run SQL Server 2017 in Docker

  • Download and install Docker for your operating system: https://www.docker.com
  • Increase Docker memory to 4 GB to run SQL Server 2017 as documented here

Copy & paste the commands below in a Terminal window to run SQL Server 2017 in Docker.

docker pull microsoft/mssql-server-linux:2017-GA

docker run --cap-add SYS_PTRACE \
           -e 'ACCEPT_EULA=Y' \
           -e 'MSSQL_SA_PASSWORD=Yukon900' \
           -e 'MSSQL_PID=Developer' \
           -p 1433:1433 \
           -d microsoft/mssql-server-linux:2017-GA

Step 2: Run the REST API web app in Docker

This REST API web app is available on Docker hub: https://hub.docker.com/r/sanagama/mssql-restapi

Copy & paste the commands below in a Terminal window to run the REST API web app in Docker and connect to SQL Server 2017 running locally in Docker.

docker pull sanagama/mssql-restapi

docker run -it -p 5000:5000 -e MSSQL_HOST=`hostname -s` sanagama/mssql-restapi

NOTE: With the above command, the REST API web app uses default values for port, database, username and password as described in environment variables

Step 3: Play with the REST API

TIP: Google Chrome with the JSON Formatter extension is a great way to play with REST APIs.

  • Launch your browser and navigate to http://localhost:5000/api/mssql
  • Click on the various links in the JSON response to navigate databases, tables, columns and table data in the SQL instance and generate scripts.

That's it, all done!

Keep reading if you want to get the source code and walk through a more advanced example with the AdventureWorks and WideWorldImporters SQL Server sample databases.

Run locally with .NET Core

Step 1: Get the source code

Download and install .NET Core for your operating system: https://www.microsoft.com/net/core

TIP: If you have Git installed then you can do git clone https://github.com/sanagama/mssql-restapi.git instead.

  • Browse to https://github.com/sanagama/mssql-restapi
  • Click Clone or Download then click Download ZIP
  • Save the ZIP file to your HOME directory as ~/mssql-restapi.zip
  • Extract the zip file to your HOME directory ~/mssql-restapi

Step 2: Run SQL Server 2017 in Docker

Launch a Terminal window and type the following commands to run SQL Server 2017 in Docker:

cd ~/mssql-restapi
cat ./scripts/1-docker-pull-mssql.sh
./scripts/1-docker-pull-mssql.sh

Step 3: Restore sample databases

Type the following commands in the Terminal window to restore a couple of sample databases to SQL Server 2017 running in Docker:

cd ~/mssql-restapi
cat ./scripts/3-docker-create-db.sh
./scripts/3-docker-create-db.sh

Step 4: Run the REST API web app locally

Type the following commands in the Terminal window to run the REST API web app locally:

cd ~/mssql-restapi
dotnet restore
dotnet build
dotnet run

Step 5: Play with the REST API

  • Launch your browser and navigate to http://localhost:5000/api/mssql
  • Click on the various links in the JSON response to navigate databases, tables, columns and table data in the SQL instance and generate scripts.

Environment variables

You can pass environment variables to the REST API web app to connect to a local or remote SQL Server instance, Azure SQL Database and Azure SQL Data Warehouse.

Environment variable Description
MSSQL_HOST Fully qualified server name. Defaults to 127.0.0.1 if not specified.
MSSQL_PORT SQL Server port. Defaults to 1433 if not specified.
MSSQL_DATABASE Initial catalog for the connection. Defaults to master if not specified.
MSSQL_USERNAME Username for SQL Server authentication. Defaults to sa if not specified.
MSSQL_PASSWORD Password for SQL Server authentication. Defaults to Yukon900 if not specified.

Use with Azure SQL Database or Azure SQL Data Warehouse

You can connect to Azure SQL Database or Azure SQL Data Warehouse by passing your connection information in environment variables when starting the REST API web app.

TIP: Follow instructions at Configure a server-level firewall rule to allow the computer running the REST API web app to connect to your Azure SQL Database or Azure SQL Data Warehouse.

TIP: Change <server>, <username> and <password> in the example below as appropriate to connect to your Azure SQL Database or Azure SQL Data Warehouse.

Type the following commands in the Terminal window to run the REST API web app in Docker:

docker run -it -p 5000:5000 \
           -e MSSQL_HOST="<server>.database.windows.net" \
           -e MSSQL_PORT="1433" \
           -e MSSQL_USERNAME="<username>" \
           -e MSSQL_PASSWORD="<password>" \
           sanagama/mssql-restapi

Type the following commands in the Terminal window to run the REST API web app locally with .NET Core:

MSSQL_HOST="<server>.database.windows.net" \
MSSQL_PORT="1433" \
MSSQL_USERNAME="<username>" \
MSSQL_PASSWORD="<password>" \
dotnet run

Motivation

My main motivation for creating this prototype was to try out the SQL Server Management Objects (SMO) APIs that recently became available on .NET Core 2.0.

See this Tweet from @sqltoolsguy for the announcement.

Developers and system administrators can finally use the nifty SMO APIs in .NET Core 2.0 client apps (like this prototype) or PowerShell cmdlets on Linux, macOS and Windows to programmatically manage SQL Server running anywhere, Azure SQL Database and Azure SQL Data Warehouse.

Take a look at the SQL Server Management Objects (SMO) Programming Guide for samples and API reference documentation.

Happy coding with SMO APIs and SQL Server running everywhere ;-)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].