0

I am trying to connect PostgreSQL database to C# application. For that I have created ODBC data source, now I need the connection string to include in C#.

Question: How to write DSN connection string for PostgreSQL in C#?

1

2 Answers 2

2

Try this

 // PostgeSQL-style connection string
   string connstring = String.Format("Server={0};Port={1};" + 
                    "User Id={2};Password={3};Database={4};",
                    tbHost.Text, tbPort.Text, tbUser.Text, 
                    tbPass.Text, tbDataBaseName.Text );
                // Making connection with Npgsql provider
   NpgsqlConnection conn = new NpgsqlConnection(connstring);
   conn.Open();
   // quite complex sql statement
   string sql = "SELECT * FROM simple_table";
   // data adapter making request from our connection
   NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);

More details here http://www.codeproject.com/Articles/30989/Using-PostgreSQL-in-your-C-NET-application-An-intr

Sign up to request clarification or add additional context in comments.

Comments

0

this worked for me

 "DefaultConnection": "User ID=postgres;Password=aamir7882;Server=localhost;Port=5432;Database=kingsurplus;Integrated Security=true;Pooling=true;

get server details and database details from pgAdmin 4

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.