Thread: [DOCS] Problem about connect Postgre using ADO.NET

[DOCS] Problem about connect Postgre using ADO.NET

From
NGUYEN TRONG LANH
Date:

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.

Please let's me know if you have any ideas to solve this.

Thanks!

-- 
-------------------------------------------------------------------++                                                      |    |    |               BRYCEN VIETNAM Co.,Ltd.             )_)  )_)  )_)              NGUYEN TRONG LANH            )___))___))___)|            Development Department           )____)____)_____)||          25 Nguyen Van Cu,Hue,Vietnam         _____|____|____|____|||__      Email: t_lanh@brycen.com.vn
---------|                   /---------  Tel: +84-(0)234-6558332  ^^^^^ ^^^^^^^^^^^^^^^^^^^^^           Mobile:+84-(0)93 8924 386    ^^^^      ^^^^     ^^^    ^^        Website:http://www.brycen.com.vn         ^^^^      ^^^                  
--------------------------------------------------------------------++

Re: [DOCS] Problem about connect Postgre using ADO.NET

From
"Charles Clavadetscher"
Date:
Hello

> -----Original Message-----
> From: pgsql-docs-owner@postgresql.org [mailto:pgsql-docs-owner@postgresql.org] On Behalf Of NGUYEN TRONG LANH
> Sent: Dienstag, 23. Mai 2017 09:18
> To: pgsql-docs@postgresql.org
> Subject: [DOCS] Problem about connect Postgre using ADO.NET
>
> 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.
>
> Please let's me know if you have any ideas to solve this.

If I understand it correctly you installed Npgsql that is a driver for PostgreSQL using ADO.NET.
What is still missing is a data source, i.e. a DSN where you choose the driver and enter connection and login
information.

How you create a DSN depends on the version of Windows you are on.

Hope this helps.
Regards
Charles

> Thanks!
>
>
>
> --
> -------------------------------------------------------------------++
>
>                |    |    |               BRYCEN VIETNAM Co.,Ltd.
>               )_)  )_)  )_)              NGUYEN TRONG LANH
>              )___))___))___)|            Development Department
>             )____)____)_____)||          25 Nguyen Van Cu,Hue,Vietnam
>           _____|____|____|____|||__      Email: t_lanh@brycen.com.vn <mailto:t_lanh@brycen.com.vn>
> ---------|                   /---------  Tel: +84-(0)234-6558332
>    ^^^^^ ^^^^^^^^^^^^^^^^^^^^^           Mobile:+84-(0)93 8924 386
>      ^^^^      ^^^^     ^^^    ^^        Website:http://www.brycen.com.vn
>           ^^^^      ^^^
> --------------------------------------------------------------------++



Re: [DOCS] Problem about connect Postgre using ADO.NET

From
Neil Anderson
Date:
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