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

Поиск
Список
Период
Сортировка
От Neil Anderson
Тема Re: [DOCS] Problem about connect Postgre using ADO.NET
Дата
Msg-id cba2fdd6-b0bf-a19d-e95d-264ec4d9d58e@postgrescompare.com
обсуждение исходный текст
Ответ на [DOCS] Problem about connect Postgre using ADO.NET  (NGUYEN TRONG LANH <t_lanh@brycen.com.vn>)
Список 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@postgrescompare.com
http://blog.postgrescompare.com


В списке pgsql-docs по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: [DOCS] Add client interfaces for Node.js and Go / Rename JDBClanguage to Java
Следующее
От: ddvkosenko@gmail.com
Дата:
Сообщение: [DOCS] SELECT , UNION INTERSECT EXCEPT clause