Skip to main content

All Questions

Filter by
Sorted by
Tagged with
114 votes
14 answers
434k views

Get ConnectionString from appsettings.json instead of being hardcoded in .NET Core 2.0 App

I have the following class in NET Core2.0 App. // required when local database does not exist or was deleted public class ToDoContextFactory : IDesignTimeDbContextFactory<AppContext> { ...
borisdj's user avatar
  • 2,441
33 votes
4 answers
29k views

Setting the SQL connection string for ASP.NET Core web app in Azure

I have created a new ASP.NET Core web application in Visual Studio 2015. I've also set up an Azure web app to pull in the app from GitHub and run it. This works fine, but I'm having trouble connecting ...
Peter's user avatar
  • 13.9k
26 votes
9 answers
45k views

How to read web.config file in .Net Core app

I have created a .Net Core API and I referenced a .Net framework application to it. The referenced Application connects to a data base and its connection string is stored in web.config file: ...
Zuhair's user avatar
  • 837
21 votes
2 answers
23k views

Configuration.GetConnectionString returns null when running asp.net core on VS Code but fine on Visual Studio

Here is my appsettings.json file { "ConnectionStrings": { "DefaultConnection": "Host=localhost;Port=5432;Database=db;User ID=postgres;Password=root" }, "Logging": { "IncludeScopes": ...
bman's user avatar
  • 3,760
17 votes
4 answers
14k views

Get Connection String in Azure Function v3

I am very confused. I want to get a connection string in an Azure v3 function (.Net Core 3.1). My local settings looks like { "IsEncrypted": false, "Values": { &...
AGuyCalledGerald's user avatar
11 votes
4 answers
15k views

Securely encrypting / decrypting appsettings.json on server

How do I protect the encryption key used to encrypt sensitive data in my web application's appsettings.json? I would like to protect sensitive data in my web application's config. In ASP.NET MVC4 ...
Ergwun's user avatar
  • 12.8k
10 votes
2 answers
29k views

Using multiple connection strings

Info I have multiple projects in my Solution, of which one is the DAL and the other is an ASP.NET MVC6 project. Since the MVC6 project is also the startup project I need to add my connection string ...
Hypenate's user avatar
  • 2,044
7 votes
1 answer
4k views

Settings keys to Azure Key Vault for sub-levels

For user secret management, I use user secrets for the development stage and I want to use Azure key vault for release and staging. I have this configuration "ConnectionStrings": { "...
dmi's user avatar
  • 132
7 votes
2 answers
21k views

How to get ConnectionString from Secrets.json in Asp.Net Core 6?

I am new to Asp.Net Core and EF. I am developing a simple CRUD from database-end, using the Secrets.json file to hide my connection string credentials. But I don't know how to reference the file using ...
Fandango68's user avatar
  • 4,682
6 votes
3 answers
25k views

.NET Core: How can I set the connection string?

I am trying to use Blazor's CRUD functions and following some article to do this. In the article, there is a part that I should put my connection in context file, but it doesn't say how to set the ...
jorjj's user avatar
  • 1,559
5 votes
1 answer
1k views

Run ASP.NET Core App in Docker Running as Custom User

I have an ASP.NET Core app connecting to a database using Integrated Security=True in the connection string, so that the credentials of the user running the app are used to connect to the database and ...
Muhammad Rehan Saeed's user avatar
5 votes
2 answers
8k views

How to secure ConnectionString and/or AppSettings in asp.net core (on-prem)

First off, I know we dont have ConnectionStrings and AppSettings per se in .Net core, but in my case I want to encrypt a ConnectionString and maybe some other application configurations stored in my ...
Inx51's user avatar
  • 1,981
4 votes
5 answers
4k views

.net core not connecting to the changed database in appsettings.json connectionstrings in visual studio debug

I am working on a .net core project, I wanted to change the connectionstring of the database in appsettings.json. I had created a duplicate database and named it originalname_fake01 and made a clone ...
TechSha's user avatar
  • 144
3 votes
1 answer
6k views

Change SQL Server Connection String Dynamically inside an ASP.Net Core application

I open one database at the start, then need to open another database based on user selecting two values. The database selection has to be at run-time and will change every time. Have tried to access ...
Mithilesh's user avatar
3 votes
1 answer
346 views

Is it safe to commit dev and production connection strings that use windows account credentials without username and password?

Are the following connection strings safe to commit to version control? If not what dangers can arise. For example if I had the following connection strings with Integrated Security=True set: In ...
Chief's user avatar
  • 953
3 votes
1 answer
3k views

How to get ConnectionString in a ClassLibrary?

Connection strings exist in appsettings.json in an ASP.Net MVC Core Project. I also have a Class Library Project in the same solution and there I want to get the connection string of web project, I am ...
Zeshan Munir's user avatar
  • 1,118
3 votes
2 answers
10k views

Get ConnectionString value from app.settings.json file in asp.net core 3.1

I am running one asp.net core application version 3.1. Where i have to read connection string value in appsettings.json file. I found many examples related to it, But none of them works for me. Below ...
V.Prasad's user avatar
  • 151
2 votes
2 answers
6k views

Connection strings & app settings in asp.net core

Haven't worked in .net core before and I am having some issues with the connection string. I am trying to get the connection string in my controller like so SqlConnection conn = new SqlConnection(...
volloi's user avatar
  • 35
2 votes
1 answer
4k views

Loading Hangfire configuration from appsettings.json in ASP.NET CORE web app

I'm trying to use Hangfire with SQL Server, reading the connection string from the appsettings.json file. It doesn't work. Only when I provide the connection string to the UseSqlServerStorage method, ...
ashilon's user avatar
  • 1,881
2 votes
2 answers
6k views

ASP.NET Core (Latest) - appsettings.json ConnectionString not overriding on Azure

I'm playing around with a small ASP.NET Core 1.1 app which I have published. Now I'm following the documentation with regards to using appsettings*.json and environment variables. So I have the ...
garfbradaz's user avatar
  • 3,464
2 votes
1 answer
516 views

Why is EF Core using the Domain\MachineName instead of the provided connection string User Id?

Question When using EF Core the SQL queries are sending the wrong username for SQL authentication. We get Login failed for user '{DOMAIN}\{MACHINE NAME}' instead of {DOMAIN}\{User Id} "Database&...
Ben's user avatar
  • 421
2 votes
2 answers
4k views

What is the connection string for SQL Server running on Mac Docker in ASP.NET Core?

I'm trying to finish the ASP.NET CORE tutorial on Pluralsight on a MAC. I'm running MSSQL server using Docker and its seems to work (i have the sql database up and running as shown here) The second ...
Phuc Truong's user avatar
2 votes
2 answers
6k views

.Net Core 3 / Entity Framework Core putting connection string in Appsettings.json not working

Still new to .NET Core but I'm trying to put my connection string in the Appsettings.json file. I'm following the Microsoft document on how to do so and I think I have all my settings correct. The ...
Caverman's user avatar
  • 3,587
2 votes
1 answer
767 views

Why my environment variables are not overriding appsettings.json

I have an application that uses ASP.NET Core Web API and mongodb, they both are containerized by docker-compose, and I don't know why my appsettings is not been overridden. This is my appsettings.json ...
GuilhermeMarques's user avatar
2 votes
1 answer
2k views

Connection string keyword 'server' is not Supported

I am deploying an ASP.NET Core MVC app with VS2017 on MacBook. When I want to update my database with dotnet ef database update --project MyProjectName I get an error: Connection string keyword '...
Behzad Hassani's user avatar
2 votes
1 answer
745 views

Why am I getting an error in my ASP.NET Core SQL Server Express Connection String?

I've recently started a new ASP.NET Core web application and I'd like to connect it to my local SQLExpress database. I've been following the documentation but I'm getting an error of "Value cannot be ...
Yanayaya's user avatar
  • 2,144
2 votes
0 answers
654 views

How to protect database connection strings on production environments of ASP.NET Core on Ubuntu?

I have a .NET Core app that is deployed on Ubuntu (using Kestrel behind Nginx). The app has a database connection string. It is defined empty in appsettings.json and I set it in Kestrel Ubuntu service ...
JustAMartin's user avatar
  • 13.6k
2 votes
0 answers
699 views

"The ConnectionString property has not been initialized." with json file

I'm trying to get the connectionstring from the json-file to the DAL-class library with: private static IConfigurationRoot config; private static string connectionString; public UserDAL() { ...
zhrgci's user avatar
  • 634
2 votes
0 answers
1k views

Asp.net core how to change Connection String at runtime?

I have 2 databases created by a migration. When my project (Asp.net core 2.2) starts, it shows a view that contains a dropdownlist of database names. Now I want any database selected anytime to change ...
topcool's user avatar
  • 2,680
2 votes
0 answers
2k views

Get connection string by environment in ConfigureServices

I have 3 connection strings. Default is for EF Core migration management, Container is for development with docker. appsettings.json { "ConnectionStrings": { "Default": "Server=localhost,1433;...
Mike Hawkins's user avatar
  • 2,284
2 votes
1 answer
1k views

The keyword 'integrated security' is not supported on this platform

I want to deployment a dotnet Core WebApplication in docker for window and use sqlserver ,this is my ConnectionString: { "ConnectionStrings": { "Default": "Server=10.0.75.0; Database=...
Zac's user avatar
  • 21
1 vote
2 answers
5k views

ASP.NET Core MVC MySQL Server Connection

I'm having issues trying to establish a connection to a server I've setup using Windows Server 2019 in ASP.NET Core MVC 3.1. The only things I've installed on the server is the MySQL suite and IIS. ...
Quantum Physics's user avatar
1 vote
1 answer
4k views

The ConnectionString property has not been initialized in .NET 8 with EF Core 8 and SQL Server 2022

I am working on a .NET 8 application using Entity Framework Core 8 and targeting SQL Server 2022 (Express Edition). Despite having a correct connection string in my appsettings.json, I am encountering ...
strasouch's user avatar
1 vote
4 answers
2k views

asp user secret problem after publish project

my connection string in user secret No problem at local but is publish and upload in server error ArgumentNullException: Value cannot be null. (Parameter 'connectionString')
jary dst's user avatar
1 vote
1 answer
9k views

ConnectionString in .NET Core 6

I'm playing around in .NET Core 6 Web API's. But I can't seem to figure out how the connection string works now. The first part here that is commented out works fine. But I need to be able to throw ...
Johandre's user avatar
1 vote
2 answers
652 views

How can I get the connection string from configuration in the InjectsAuthElements methods in Startup.cs

I am trying to configure elmah with sql server. The configuration I see are of this form public class Startup { public void ConfigureServices(IServiceCollection services) { ... } ...
Ant's user avatar
  • 277
1 vote
2 answers
2k views

how configure appsettings.json to have a different connection string from the project when I'm in local

I'm on .NET 5 in an API, and in the appsettings.json I have the following: The project I'm working on has a connection string like this "DefaultConnection": "Data Source=someserverAWS....
armando t's user avatar
  • 149
1 vote
1 answer
5k views

Failed to load resource: net::ERR_CONNECTION_TIMED_OUT on remote but works fine on localhost

i have react with asp.net core website . it worked fine on localhost but when published on iis remote server the timeout error occurs. the front-end (react client) and back-end(server) asp.netcore ...
Fiaz Ahmed Ranjha's user avatar
1 vote
1 answer
3k views

Dynamic connection strings appsettings.json Asp.NetCore

I'm really new in this API development, so I have the next question. Is it possible to get the DB name at run time for my connection string? This because the user will be sending the DB name through a ...
Eunice Rayas's user avatar
1 vote
1 answer
1k views

How to inject connection string using ASP.NET Core DI

With Unity one can do something like this: .RegisterType<IControllerFactory, MyControllerFactory>( new InjectionConstructor("connectionstring goes here")); Is it possible to do the same in ...
Yola's user avatar
  • 18.9k
1 vote
1 answer
5k views

IBM DB2 Core: Connection string for ASP.NET Core 2.1 and Microsoft Enterprise Libraries

I'm using this Microsoft.EnterpriseLibrary port for .Net Core. It requires a configuration file app.config with the connection string specified in it. I tried using the same connection string I use in ...
amedina's user avatar
  • 3,186
1 vote
1 answer
51 views

How reduce code repitition in the given code?

class TransactionAccess { public static void GetTransactions() { string connString = "Host=localhost;Username=postgres;Password=1234;Database=ExpenseManagerDB"; using ...
bahanu's user avatar
  • 11
1 vote
0 answers
3k views

Disable TLS on SQL-Connection in ASP.NET Core

I'm using Microsoft.Data.SqlClient for dealing with MS SQL-Server connections. Now, for debug reasons I need to temporarily disable TLS encryption of the SqlConnection so I can monitor it with ...
Andreas H.'s user avatar
1 vote
0 answers
363 views

Asp.net Core Mysql 'connectionString' error

I used entityframework to migrate my sql database but here is error to connect mysql host. Error during run context.Database.Migrate() : System.InvalidOperationException: 'An exception has been ...
sadullah zolfqar's user avatar
1 vote
0 answers
434 views

How to change localDb connection String to SQL Server for Linux deployment?

I am beginner and trying to deploy my first app on linux server but localDB isn't supported. How I convert this localDB connection string to SQL Server. I searched and found only in xlm everywhere. ...
imabdullah's user avatar
1 vote
0 answers
38 views

Dynamic connection to Database ASP.NET

I want write autorization system in asp.net - user of Postgres (which created throws CREATE ROLE...) entering login and password and working with own tables. Problem is i working in ASP.NET core and ...
Travis Bincle's user avatar
1 vote
1 answer
363 views

How to access connectionString in your model?

How can i access the connectionString inside my model? I'm using Dapper. Most of the solutions i found were using EntityFramework and not Dapper. This is working on my local machine (macOS): public ...
ttt's user avatar
  • 6,596
1 vote
1 answer
2k views

Access asp net core application connection string from another project

I have a ASP NET CORE project, where I have a connection string and my dbcontext is in a .net 4.52 class library project. I would like to know how to access the connection string from the asp net core ...
Bernardo Magalhães's user avatar
1 vote
1 answer
803 views

Connection string without localhost .net core

This question might be a little easy and a bit stupid. But here i go. im working with more people on making a .net core project. And they have to change the connection string every time because its ...
V.David's user avatar
  • 75
0 votes
3 answers
101 views

How do I make my connectionString available to my DataAccess Class using the builder (WebApplication.CreateBuilder)

I have my connection string set in the appsettings.json file and I can see it in the Main using Console.WriteLine so I know I am getting it to the program.cs correctly. var builder = WebApplication....
Buck Hicks's user avatar
  • 1,564