Connect application to Postgresql?

Asked

Viewed 5,572 times

0

Rstou wanting to connect a simple application made in C# to a Postgresql database, what I would like to know is if the procedure is similar to Java, in which I have to create a connection class, a class with the get’s and set’s of entities to manipulate the data?

I saw in Visual Studio that he has an option to Connect to Database and I thought Visual Studio was already automated in relation to that.

  • look, check out this article: http://www.macoratti.net/14/07/ef6_pgsql1.htm

2 answers

1

The connection is done similarly. In Java, you connect to the database via JDBC. Files . jar

In C# the connection is made through ADO.NET. Just like in Java, you will need a mobile phone to access the database. In this case, the DLL Npgsql.dll

See a simple example of a connection below.


using System;
using System.Data;
using Npgsql; //Referencia do provider de conexão do Postgresql.  

public class Npgsqlusermanual { public Static void Main(String[] args) { Npgsqlconnection Conn = new Npgsqlconnection("Server=127.0.0.1;Port=5432;User Id=joe;Password=secret;Database=joedata;"); Conn. Open(); Conn. Close(); } }

0

Here it is:
string serverdb = "IP"; dbdb string = "Basedata";

 string userdb = "Username";
 string passdb = "Password";

 string connectionString = "Server=" + serverdb + ";Port=5432;UserID=" + userdb + ";password=" + passdb + ";Database=" + dbdb + ";";


public Boolean conecta()
{
    //Estabelece Ligações a Bases de Dados
    try
    {
        this.coneccao = new NpgsqlConnection(connectionString);
        coneccao.Open();
    }
    catch (Exception )
    {
        MessageBox.Show(ex.Message, "Erro de ligação");
      }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.