The first time you encounter a remote access PostgreSQL database in a project, there are often errors connecting to the database, and the connection string is garbled
Solution Solutions
To add a connection string to a configuration file
<add key="information" value="server=182.76.17.254; Port=5432;database=wos;uid=postgres;pwd=postgres; Encoding=unicode" />
Background code
string connectionString = ConfigurationManager.AppSettings ["Information"];
// Create a database connection object
NpgsqlConnection con = new NpgsqlConnection (connectionString);
// Define the query statement, here it is better to write the SQL statement in SQL and verify that it is copied and pasted correctly. Operating efficiency)
string strSql = "select * from terminals";
//con.Open();//Open the database connection (Of course, this sentence can not be written)
NpgsqlDataAdapter sda = new NpgsqlDataAdapter (strSql, con);
DataSet ds = new DataSet ();
sda.Fill (ds, "terminals"); // Put the execution data in the data set
//pds.DataSource = ds.Tables [0] .DefaultView; // Put the data in the data set into the paging data source
//DataList1.DataSource = pds; // Bind Datalist
DataList1.DataSource = ds.Tables ["terminals"];
DataList1.DataBind ();
con.Close ();
Last connection succeeded
C # remote Connect PostgreSQL database