Connect to PostgreSQL in c# applications using Npgsql

c# npgsql postgresql csharp 5 years, 5 months ago
using System.Text; using System.Threading.Tasks; using IronPython.Hosting; using System.Data;//Create Dataset, DataTable, DataRow using Npgsql;//Classes to interact and connect with PostgreSql namespace DatabaseExamples { class Program { static void Main(string[] args) { NpgsqlConnection con = null; try { con = new NpgsqlConnection("Host=localhost;Port=5433;Database=Test;Username=postgres;Password=koder123;"); con.Open(); }catch(NpgsqlException npgEx){ throw npgEx; }finally{ con.Close(); } } } }
2516
Instructions

By default PostgreSql installed on 5432 port. If you have already configured the port while installing pgAdmin, then try to mention the port number under port key in connection string , then only you can able to do database operations.In the other case without the port number also works fine.

Npgsql is a dll can be downloaded from *"Manage NuGet Packages"

Posted By
Subscribe to an event from code behind in c#.
using System.Windows;
using System.Windows.Input;

c# wpf
harika
Change the rectangle fill color using trigger
<Window x:Class="Train.MainWindow"
        xmlns="http://schemas.microsoft.
        xmlns:x="http://schemas.microsof
c# wpf ui
harika
example of How to use Json Objects in c#
class Program
{
    static void Main(string[] args)
json c# csharp
harika
How to center a wpf App/ Window ?
namespace KoderPLace
{
    public partial class Window1 : Windo
csharp c# wpf ui
harika
How to connect to PostgreSQL database and dis
import psycopg2

conn = psycopg2.connect(host="localhost"
python psycopg2 postgresql
kishore_kumar
Move a table to other schema in Postgres
ALTER TABLE table_name SET SCHEMA new_sc
sql postgresql
kishore_kumar
How to stop the PostgreSQL manually?
show data_directory;   //To see the dire

pg_ctl -D /var/lib/postgresql/data stop 
manual stop postgresql mysql
Reshma
Adding a new auto increment column to a table
-- New versions of postgres
-- adding as primary key

sql postgres postgresql
kishore_kumar
How to delete SEQUENCE in postgresql
drop sequence sequence_name;
sequence postgresql mysql
Reshma
How to copy a table from one database to anot
pg_dump -U user1 db_name_old_db | psql -
database postgresql copy table mysql
Reshma
How to dump a database in postgresql
sudo -i -u postgres

psql
dump postgresql sql
Reshma