From 17125a2012714210778afce07a90de15adeb4c88 Mon Sep 17 00:00:00 2001 From: Mikhail Preyskurantov <5574159+mpreyskurantov@users.noreply.github.com> Date: Tue, 18 Jun 2024 18:43:38 +0300 Subject: [PATCH] Move Sample app connection string to configuration file (#621) --- net/Sample/Program.cs | 2 +- net/Sample/appsettings.json | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 net/Sample/appsettings.json diff --git a/net/Sample/Program.cs b/net/Sample/Program.cs index 5aa338f1..3d2ee748 100644 --- a/net/Sample/Program.cs +++ b/net/Sample/Program.cs @@ -20,7 +20,7 @@ public static void Main(string[] args) { .AddEntityFrameworkSqlServer() .AddDbContext(options => options //.UseSqlServer("Server=.\\SQLEXPRESS; Database=Northwind; Trusted_Connection=True") - .UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB; Database=Northwind; Integrated Security=True; MultipleActiveResultSets=True; App=EntityFramework") + .UseSqlServer(builder.Configuration.GetConnectionString("NorthwindConnectionString")) ); var app = builder.Build(); diff --git a/net/Sample/appsettings.json b/net/Sample/appsettings.json new file mode 100644 index 00000000..2877a30f --- /dev/null +++ b/net/Sample/appsettings.json @@ -0,0 +1,6 @@ +{ + "ConnectionStrings": { + "NorthwindConnectionString": "Data Source=(localdb)\\MSSQLLocalDB; Database=Northwind; Integrated Security=True; MultipleActiveResultSets=True; App=EntityFramework", + "NorthwindConnectionStringIis": "Data Source=.; Database=Northwind; User Id=; Password=; MultipleActiveResultSets=True; App=EntityFramework; TrustServerCertificate=True" + } +}