jiheielf
jiheielf
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
When I go into the terminal of the container I wasn't able to ping to the ip, but when I do it in on my docker host machine, it was all fine
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
I think I have configured it already, otherwise the program I deployed locally shouldn't be able to connect to it..?
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
But I'm getting error when I try to connect to the sql server from the container...
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Company's decision..
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Containers are Linux contianers
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Sql server is on a windows server, docker is held on another windows11 machine but in the same network
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Yes
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Hi, I have just checked this, but this exmaple seems trying to make a new container that connects to a local sql server rather than a remote one. My remote sql server is running in a windows server on another machine...
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Or does it mean I need to start up a sql server container that connects to the remote server and then connect my program onto this new sql server container...?
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Sorry I didn't understand it, in my code the connection string is this "Data Source=xxx.xx.xxx.xx,1433;initial Catalog=xxxx;User ID=xxxx;Password=xxxxxx;MultipleActiveResultSets=true" but the Data Source should be another format that needs to be compatable in the container's internal linux environment?
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Sorry just to double check if I didn't get it wrong, does that mean I need to firstly set up the connection from the container internal linux environment to be able to connect to the remote sql server or the remote ip address and then my program as a container can then be able to using EF core to interact with it?
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Let me have a check
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
and it is a linux container
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
from my windows terminal, when I run the container I set the --network = host
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
Sorry I'm a beginner on Docker, what does that mean?
46 replies
CC#
Created by jiheielf on 4/16/2025 in #help
✅ Docker Container Can't connect to remote SQL Server
No it is a remote sql server, have to connect it using the ip address
46 replies
CC#
Created by jiheielf on 3/28/2025 in #help
Worker Service .NET8 how to gracefully shutdown as a docker container
namespace MyWorkerService
{
public class Worker : BackgroundService, IHostedLifecycleService
{
private readonly ILogger<Worker> _logger;
private volatile bool myBool = true;

public Worker(ILogger<Worker> logger)
{
_logger = logger;
}

public Task StartingAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task StartedAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task StoppingAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Stopping - performing cleanup");

// Start cleanup in background
Task.Run(() =>
{
Thread.Sleep(3000); // Simulate cleanup work
_logger.LogInformation("Cleanup finished");
myBool = false; // This will allow the loop to exit
});

// Wait for the cleanup to complete
while (myBool)
{
Thread.Sleep(1000); // Short sleep to avoid CPU spinning
}

_logger.LogInformation("Stopping completed");
return Task.CompletedTask;
}

public Task StoppedAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(1000, stoppingToken);
}
}
}
}
namespace MyWorkerService
{
public class Worker : BackgroundService, IHostedLifecycleService
{
private readonly ILogger<Worker> _logger;
private volatile bool myBool = true;

public Worker(ILogger<Worker> logger)
{
_logger = logger;
}

public Task StartingAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task StartedAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

public Task StoppingAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Stopping - performing cleanup");

// Start cleanup in background
Task.Run(() =>
{
Thread.Sleep(3000); // Simulate cleanup work
_logger.LogInformation("Cleanup finished");
myBool = false; // This will allow the loop to exit
});

// Wait for the cleanup to complete
while (myBool)
{
Thread.Sleep(1000); // Short sleep to avoid CPU spinning
}

_logger.LogInformation("Stopping completed");
return Task.CompletedTask;
}

public Task StoppedAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(1000, stoppingToken);
}
}
}
}
25 replies
CC#
Created by jiheielf on 3/28/2025 in #help
Worker Service .NET8 how to gracefully shutdown as a docker container
Hi all, so I have tried to search for any lifecycle related stuff for the worker service, and I have found the interface called IHostedLifecycleService. So in my application I will have a boolean value that will be changed by the long run process and in the StoppingAsync method it will just wait until the process change the boolean. But it seems that just won't work for docker container...any additional ideas?
25 replies