From: Neil Anderson <neil@postgrescompare.com>
To: NGUYEN TRONG LANH <t_lanh@brycen.com.vn>
To: pgsql-docs@postgresql.org
Subject: Re: Problem about connect Postgre using ADO.NET
Date: Sat, 10 Jun 2017 19:20:08 -0400
Message-ID: <cba2fdd6-b0bf-a19d-e95d-264ec4d9d58e@postgrescompare.com> (raw)
In-Reply-To: <cef19a6a-5835-403a-9e32-024ce40986f5@brycen.com.vn>
References: <cef19a6a-5835-403a-9e32-024ce40986f5@brycen.com.vn>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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@postgrescompare.com
http://blog.postgrescompare.com
--
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-docs@postgresql.org
Cc: neil@postgrescompare.com, t_lanh@brycen.com.vn
Subject: Re: Problem about connect Postgre using ADO.NET
In-Reply-To: <cba2fdd6-b0bf-a19d-e95d-264ec4d9d58e@postgrescompare.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox