-
Book Overview & Buying
-
Table Of Contents
The C# Workshop
By :
Once you have installed .NET, the CLI can be used to create and configure projects for use with VS Code. To launch the .NET CLI, run the following at the command prompt:
dotnet
If .NET is installed correctly, you will see the following message on your screen:
Usage: dotnet [options] Usage: dotnet [path-to-application]
Once you have the CLI installed to configure projects with VS Code, you need to know about the powerful open source object-relational database system that uses and extends the SQL language that is, PostgreSQL.
Note
You will first go through the instructions to install PostgreSQL for Windows followed by macOS, and then by Linux.
PostgreSQL has been used in Chapter 6, Entity Framework with SQL Server. Before you proceed with that chapter, you must install PostgreSQL on your system using the following steps:
Figure 0.8: Latest PostgreSQL versions for each platform
Note
The screen shown in Figure 0.8 may change depending upon the latest release from the vendor.
Next button. The Setup PostgreSQL screen gets displayed:
Figure 0.9: Welcome screen for PostgreSQL upload
Next button to move to the next screen which asks for the installation directory details:
Figure 0.10: PostgreSQL default installation directory
Installation Directory unchanged and click the Next button.PostgreSQL Server refers to the database.pgAdmin 4 is the database management tool.Stack Builder is the PostgreSQL environment builder (optional).Command Line Tools work with the database using a command line.
Figure 0.11: The PostgreSQL components selected to proceed
Next button.
Figure 0.12: The directory for storing data
Next button to continue. The next screen asks you to enter the password.Password.Retype password for the database superuser:
Figure 0.13: Providing password for database superuser
Next button to continue.5432. Use the default port—that is, 5432:
Figure 0.14: Selecting Port
Next button.[Default locale]:
Figure 0.15: Selecting the locale for the Database cluster
Next button.Next button to go ahead:
Figure 0.16: Setup window showing ready to install message
Next button (leaving the default settings unchanged) until the installation process begins.Launch Stack Builder at exit option:
Figure 0.17: Installation complete with Stack Builder unchecked
The Stack Builder is used to download and install additional tools. The default installation contains all tools needed for the exercises and activities.
Finish button.pgAdmin4 from Windows.Password for connecting to any database inside PostgreSQL in the Set Master Password window:
Figure 0.18: Setting Master Password for connecting to a PostgreSQL server
Note
It is better to type a password that you can easily memorize as it will be used to manage all your other credentials.
OK button.Server by clicking the arrow beside it.Save password for security reasons:
Figure 0.19: Setting the postgres user password for the PostgreSQL server
PostgreSQL server password is the password you will use when connecting to the PostgreSQL server and using the postgres user.
OK button. You will see the pgAdmin dashboard:
Figure 0.20: pgAdmin 4 dashboard window
In order to explore the pgAdmin dashboard, move to the Exploring pgAdmin Dashboard section.
Install PostgreSQL on your macOS using the following steps:
Note
The following screenshots were taken for version 14.4 on macOS Monterey (version 12.2).
Figure 0.21: Installation page for PostgreSQL
installer file to launch the PostgreSQL Setup Wizard:
Figure 0.22: Launching the PostgreSQL setup wizard
Figure 0.23: Selecting the installation directory
Next button.pgAdmin 4Stack Builder component:
Figure 0.24: Selecting the components for installation
Next button.
Figure 0.25: Specifying the data directory
Next button.Password for the Postgres database superuser:
Figure 0.26: Setting the password
Make sure to note down the password safely for logging in to the PostgreSQL database.
Next button.Set the port number where you want to run the PostgreSQL server. Here the default Port number is set as 5432:
Figure 0.27: Specifying the port number
Next button.[Default locale] is the locale selected for macOS:
Figure 0.28: Selecting the locale specification
Next button.
Figure 0.29: Pre Installation summary page
Finally, click on the Next button to start the installation process of the PostgreSQL database server on your system:
Figure 0.30: Ready to Install page before starting the installation process
Figure 0.31: Setup Installation in progress
Next button. The next screen displays the message that the PostgreSQL installation is complete on your system:
Figure 0.32: Success message showing the setup as complete
Finish button once the installation gets complete.pgAdmin 4 icon to launch it from your Launchpad.OK button. You will now see the pgAdmin dashboard.This completes the installation of PostgreSQL for the macOS. The next section will familiarize you with the PostgreSQL interface.
Once you have installed PostgreSQL in Windows and macOS, follow these steps to grasp the interface better:
pgAdmin4 from Windows/ macOS (in case pgAdmin is not open on your system).Servers option on the left:
Figure 0.33: Clicking on Servers to create a database
PostgreSQL 14.Create option.Database… option to create a new database:
Figure 0.34: Creating a new database
This will open a Create – Database window.
TestDatabase.Owner as postgres:
Figure 0.35: Selecting the owner of the database
Save button. This will create a database.Databases and choose the Refresh button:
Figure 0.36: Clicking the Refresh… button after right-clicking Databases
A database with the name TestDatabase is now displayed within the dashboard:
Figure 0.37: TestDatabase ready for use
Now your database is ready to be used for Windows and Mac environments.
In this example, you are using Ubuntu 20.04 for installation. Perform the following steps to do so:
$ sudo apt update
$ sudo apt install postgresql postgresql-contrib
Note
To install only PostgreSQL (not recommended without additional packages), use the command $ sudo apt install postgresql and then press Enter.
This installation process creates a user account called postgres that has the default Postgres role.
There are two ways to start the PostgreSQL CLI using the postgres user account:
Option 1 is as follows:
$ sudo -i -u postgres
$ psql
Note
Sometimes, while executing the preceding command, a psql error may be displayed as could not connect to server: No such file or directory. This is because of a port issue on your system. Due to this port blockage, the PostgreSQL application may not work. You can try the command again after some time.
$ \q
Option 2 is as follows:
$ sudo -u postgres psql
$ \q
conninfo command:$ sudo -u postgres psql $ \conninfo $ \q
Using this command, you can ensure that you are connected to the postgres database as the postgres user via port 5432. If you don't want to use the default user, postgres, you can create a new user for you.
Enter:$ sudo -u postgres createuser –interactive
The preceding command will ask the user to add the name of the role and its type.
testUser.y when prompted to set a new role to be a superuser:Prompt: Enter the name of the role to add: testUser Shall the new role be a superuser? (y/n) y
This will create a new user with the name testUser.
testdb using the following command:$ sudo -u postgres createdb testdb
$ sudo -u testUser psql -d testdb
$ \conninfo
$ \q
Using this command, you can ensure that you are connected to the testdb database as the testUser user via port 5432.
With these steps, you have completed the PostgreSQL installation for Ubuntu.
Change the font size
Change margin width
Change background colour