I have Asp.net Project And I Use Docker Compose
I want To Connect Sql With Windows Authentication
But I Can't
Can You Help Me ?
appsetting :
{
"ConnectionStrings":{
"DefaultConnection": "Server=*******;Database=******;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Docker-Compose :
version: '3.4'
services:
connectsqltodocker:
image: ${DOCKER_REGISTRY-}connectsqltodocker
build:
context: .
dockerfile: ConnectSqlToDocker/Dockerfile
depends_on:
- OKKouroshCard
OKKouroshCard:
image: "mcr.microsoft.com/mssql/server"
Related
I get an error when creating EF migrations in my C# ASP.NET MVC project:
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Specified argument was out of the range of valid values. (Parameter 'timeout')
I have installed the mentioned package (it wasn't installed originally) to the version in line with the other packages across the projects, which was 6.01, I have updated it to 7.0 and have updated the others. Has anyone else experienced this? I can't see anything else related to timeout online.
Edit:
This is a sample of the logs around the migration in the PMC
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'timeout')
at System.Threading.Tasks.Task.Wait(TimeSpan timeout)
at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.CreateHost()
at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass10_0.b__0(String[] args)
at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass13_0.b__3(String[] args)
at Microsoft.EntityFrameworkCore.Design.Internal.AppServiceProviderFactory.CreateFromHosting(String[] args)
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Specified argument was out of the range of valid values. (Parameter 'timeout')
No application service provider was found.
This is a copy of my appSettings.json file:
{
"Version": "",
"Vault": "",
"ClientId": "",
"ClientSecret": "",
"CorsAllowedOrigins": "",
"Logging": {
"LogLevel": {
"Default": "Warning",
"System": "Warning",
"Microsoft": "Warning"
}
},
"ConnectionStrings": {
"CommonDbContext": "Server=(localdb)\\mssqllocaldb;Database=database1;Trusted_Connection=True;MultipleActiveResultSets=true",
"ApplicationDbContext": "Server=(localdb)\\mssqllocaldb;Database=database2;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"API": "https://localhost:44383",
"API": "https://localhost:44325",
"API": "https://localhost:44317",
"API": "https://localhost:44312",
"API": "https://localhost:44311"
}
I am working on .net framework 4.7.2 web API which doesn't have appsetting.json.
I wonder where should I configure the below setting for Microsoft.Extension.Logging?
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
and Bind it to LoggerFilterOption on Startup?
Below seems not to work:
LoggerFilterOptions options = new LoggerFilterOptions();
var config = UnityConfig.Container.Resolve<IConfiguration>();
config.GetSection("Logging").Bind(options);
I want to control MinLogLevel and Rules (LoggerFilterOption)through the web.config, Can that be achieved?
I am trying to upgrade the .netcore framework from 2.2 to 3.1 .
But I want to use IHostingEnvironment, IWebHostBuilder and AddNewtonsoftJson in 3.1 also.
(I know they should be replaced but if I will do so, code refactoring will be required, which i don't need right now).
When I am executing an api using swagger then getting 500 error with message:
can't parse JSON. Raw result:
System.Exception: Method not found: 'Microsoft.Extensions.Logging.ILoggerFactory Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsole(Microsoft.Extensions.Logging.ILoggerFactory, Microsoft.Extensions.Logging.LogLevel)'.
And this is the beginning of stack trace
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.MissingMethodException: Method not found: 'Microsoft.Extensions.Logging.ILoggerFactory Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsole(Microsoft.Extensions.Logging.ILoggerFactory, Microsoft.Extensions.Logging.LogLevel)'.
I am configuring Logger only in Program.cs .
public static IWebHostBuilder CreateWebHostBuilder (string[] args) =>
WebHost.CreateDefaultBuilder (args)
.UseUrls ("http://0.0.0.0:5000")
.ConfigureLogging ((hostingContext, logging) => {
logging.AddConfiguration (hostingContext.Configuration.GetSection ("Logging"));
logging.AddConsole ();
logging.AddApplicationInsights ();
})
.UseStartup<Startup> ();
}
Configurations in appsettings.json
"Logging": {
"IncludeScopes": false,
"ApplicationInsights": {
"LogLevel": {
"Default": "Warning",
"Microsoft": "Error"
}
},
"LogLevel": {
"Default": "Information",
"System": "Warning",
"Microsoft": "Warning"
},
"Console": {
"IncludeScopes": true
}
}
I am not understanding why it's not working.
Note: I have 6 APIs in this project and 1 is working successfully with the above changes and 5 are failing with the above error.
As I read in discussion John has given correct suggestion. In visual Studio go to NuGet - Solution and update all the package which has require to update.
I have an ASP.NET Core 3.1 API running on Microsoft Azure App Service.
I have set up an ILogger into the app and I use it extensively to monitor the behavior of the API. I would like to be able to see those messages real time into the Azure Log Stream of the app portal.
I managed to get logs after registering the AzureWebAppDiagnostics into Program.cs as follows:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
logging.AddAzureWebAppDiagnostics();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
The problem is that messages I logged explicitly, using
logger.LogInformation("whatever message")
are mixed with system messages and becomes flooded: Entity Framework commands, Microsoft.Hosting.Lifetime messages, and multiple other informative messages.
How can I set up the system in a way that I get only error/warning messages from the system, and informative messages from my app code.
I tried to change the appsettings.json as follows, but it seems to have no effect at all :
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Error",
"Microsoft.*": "Error",
"System": "Error",
"Microsoft.EntityFrameworkCore.*": "Warning"
}
}
I deleted as well the appsettings.development.json file just in case, as suggested here.
What am I doing wrong?
Actually, after throrough researches, the solution was provided here
You need to add AzureAppServicesBlob and AzureAppServicesFile configuration into your configuration file, they seem to be the one taken into account by the Azure Log Stream.
So I added the following part :
"AzureAppServicesBlob": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Error",
"System": "Error"
}
},
"AzureAppServicesFile": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Error",
"System": "Error"
}
}
It's not wildcarded in the configuration. It's simply a namespace prefix: use Microsoft.EntityFrameworkCore as the property name.
Good day!
I am struggling on how to connect existing database with existing data to my API project. And also how do I know if I'm already connected? I am using .NET Core 1.1 and my database is SQL Server 2012.
appsettings.json :
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=;User Id=sa;Password=Passw0rd;MultipleActiveResultSets=True"
}
}
}
Startup.cs - ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddDbContext<DefaultConnection>(
options => options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
}
I am following this tutorial but it seems that this creates new database.
http://www.mithunvp.com/aspnet-core-web-api-entity-framework-core/
Would highly appreciate all your comments/solutions/suggestions.
Thank you very much!
You need to add the name of the database into that line :
"DefaultConnection": "Server=COGSOL-LAP13;Database=DATABASENAME;UserId=sa;Password=Passw0rd;MultipleActiveResultSets=True"
And as CodeCaster comment says, you should use the name of the server too
You also have a space between User and Id User Id should be
UserId