Permalink
Browse files

ADD Connection to mssql-server-linux container from aspnetcore container

  • Loading branch information...
Vivien FABING
Vivien FABING committed Nov 13, 2017
1 parent 4325a92 commit 267c0d4b7ee5d4d1f421c19010f61b07faadc8fb
@@ -3,17 +3,41 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Data.SqlClient;
using Microsoft.Extensions.Configuration;
namespace OMC.DockerApi.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
private IConfiguration _configuration;
public ValuesController(IConfiguration configuration)
{
_configuration = configuration;
}
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
var result = new List<string>();
using (var connection = new SqlConnection(_configuration.GetConnectionString("ValuesDatabase")))
{
connection.Open();
using (var command = new SqlCommand("SELECT * FROM [ValuesDatabase].[dbo].[Values]", connection))
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
result.Add(reader.GetString(1));
}
}
}
return result;
}
// GET api/values/5
@@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
</ItemGroup>
<ItemGroup>
View
@@ -23,6 +23,7 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped((s) => Configuration);
services.AddMvc();
}
@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"ValuesDatabase": "Server=localhost;Database=madb;Connection Timeout=30;MultipleActiveResultSets=true;Integrated security=true;"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
@@ -0,0 +1,13 @@
{
"ConnectionStrings": {
"ValuesDatabase": "Server=mssql;Database=ValuesDatabase;User=sa;Password=YourStrong!Passw0rd"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"ValuesDatabase": ""
},
"Logging": {
"IncludeScopes": false,
"Debug": {
@@ -3,6 +3,13 @@ version: '3'
services:
omc.dockerapi:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_ENVIRONMENT=Docker
ports:
- "80"
mssql:
environment:
SA_PASSWORD: "YourStrong!Passw0rd"
ACCEPT_EULA: "Y"
MSSQL_PID: "Express"
volumes:
- C:\Users\VivienFABING\Desktop\mytestvolume:/var/opt/mssql
View
@@ -6,3 +6,9 @@ services:
build:
context: ./OMC.DockerApi
dockerfile: Dockerfile
depends_on:
- mssql
mssql:
image: "microsoft/mssql-server-linux"
ports:
- "1433:1433"

0 comments on commit 267c0d4

Please sign in to comment.