Skip to content

Commit

Permalink
Add configurationBuilder to get Connectionstring in Project
Browse files Browse the repository at this point in the history
  • Loading branch information
WALEED-NET committed Aug 31, 2023
1 parent 25728dc commit 9801e8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions 02ConnectionString/02ConnectionString.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>

</Project>
11 changes: 9 additions & 2 deletions 02ConnectionString/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
namespace _02ConnectionString
using Microsoft.Extensions.Configuration;

namespace _02ConnectionString
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();

Console.WriteLine(configuration.GetSection("constr").Value);
Console.ReadKey();
}
}
}
1 change: 1 addition & 0 deletions 02ConnectionString/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"constr": "Data Source=MSI;Initial Catalog=DigitalCurrency;Integrated Security=True;Connect Timeout=30;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False"
}

0 comments on commit 9801e8f

Please sign in to comment.