Re: Problem about connect Postgre using ADO.NET

From: Neil Anderson <neil(at)postgrescompare(dot)com>
To: NGUYEN TRONG LANH <t_lanh(at)brycen(dot)com(dot)vn>, pgsql-docs(at)postgresql(dot)org
Subject: Re: Problem about connect Postgre using ADO.NET
Date: 2017-06-10 23:20:08
Message-ID: cba2fdd6-b0bf-a19d-e95d-264ec4d9d58e@postgrescompare.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On 2017-05-23 3:17 AM, NGUYEN TRONG LANH wrote:
> Hello pgsql support team!
>
> At first, forgive me if the content of the email is not your
> responsibility. I have problem when I try connect Postgre using ADO.NET,
> I not see PostgreSQL in Data Source list.
>
> I have done to install Npgsql package, install Npgsql PostgreSQL
> extension but the problem is not solve.

Hi, I use Npgsql in my project. I'm not sure what you mean by 'I do not
see PostgreSQL in Data Source list', Npgsql does not discover the server
for you, you must provide it with a connection string, create a
connection and execute commands. Here is a code example:

var connString =
"Host=localhost;Username=postgres;Password=passwrd;Database=postgres";

using (var conn = new NpgsqlConnection(connString))
{
conn.Open();

// Insert some data
using (var cmd = new NpgsqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO data (some_field) VALUES (@p)";
cmd.Parameters.AddWithValue("p", "Hello world");
cmd.ExecuteNonQuery();
}

// Retrieve all rows
using (var cmd = new NpgsqlCommand("SELECT some_field FROM data",
conn))
using (var reader = cmd.ExecuteReader())
while (reader.Read())
Console.WriteLine(reader.GetString(0));
}

For future reference Npgsql have wonderful documentation here
http://www.npgsql.org/index.html, and they prefer questions be posted to
Stack Overflow.

--
Neil Anderson
neil(at)postgrescompare(dot)com
http://blog.postgrescompare.com

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message ddvkosenko 2017-06-12 16:16:25 SELECT , UNION INTERSECT EXCEPT clause
Previous Message Peter Eisentraut 2017-06-10 00:37:16 Re: Add client interfaces for Node.js and Go / Rename JDBC language to Java