This project shows how to use Ngpsql to connect a C# console app to the Pagila database.
-
Fork this repo on GitHub.
-
Go to Visual Studio to clone your forked repo.
Gitmenu ->Clone Repository- Under
Browse Repositories, click theGitHubbutton. - Select your
NgpsqlDemorepo and clickClone.
-
Go to Solution Explorer in Visual Studio
- Right-click
NpgsqlDemo- Select
Manage Nuget Packages - Browse
- Search for
Microsoft.Extensions.Configuration- Install
- Search for
Microsoft.Extensions.Configuration.Json- Install
- Search for
Npgsql- Install
- Search for
- Select
- Right-click
NpgsqlDemo- Add -> New Item
- Name the file
appsettings.json
- Right-click
-
Paste this code in appsettings.json:
"ConnectionStrings": {
"Pagila": "Host=YOURSERVERNAME;Port=5432;Database=pagila;Username=YOURUSERNAME;Password=YOURPASSWORD"
}
}```