What is the connectionstring to connect with postgresql using ODBC driver? - postgresql

I am currently working with a task to connect with PostgreSQL and retrieve data from that DB to my .net application,I am using the code like
OdbcConnection con = new OdbcConnection("Driver={PostgreSQL };Server=localhost;Port=2012;Database=DataCenter;Uid=postgres;Pwd=post#123;");
but it is throwing an ODBException. Please suggest me a code.

You may try that:
Driver={PostgreSQL};Server=IP
address;Port=5432;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
You can definitely find more information on this website: http://www.connectionstrings.com/
And in your case particularely on this page: http://www.connectionstrings.com/postgre-sql#p51
If it does not solve your problem it is that the problem doesn't come from the connection string but your configuration of PostgreSQL. You might want to check that you're able to connect to the server using "psql" (for example) from your client computer.
Regards

For Ex:
string connstring = String.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};",
"localhost", "5432", "postgres", "metin", "ATALAY");

Related

postgresql pg library taking windows username instead of postgresql

i am using pg lib in strapi application, where initially it creates postgres connection using correct postgresql username(postgres), database name(strapi_db) and password(postgres) but after login it changed it to connect using my windows 10 username(rayappan.a, and database as rayappan.a). it seems strange to me because i never configured anywhere to use my windows credentials for POSTGRESQL connection. please any one tell me how to fix username connection issue
Regards,
Rayappan Antoniraj
Take a look into https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING . It states that username:
Defaults to be the same as the operating system name of the user running the application."
The database name:
Defaults to be the same as the user name.
So it seems a new connection with parameters not set is made.

How to get pgbouncer stats with .NET (c#)

I want to show some pgbouncer stats in a simple wpf client (npgsql), but I can't connect to pgbouncer. The connect to a postgresql database via pgbouncer is working well, but the connect to pgbouncer admin database is not. With the used credentials I don't have any problems to connect with psql.
The Code:
var connString = "Server=X.X.X.X;Port=6432;User Id=pgbouncer;Password=myPw;Database=pgbouncer;";
using (var con = new NpgsqlConnection(connString))
{
await con.OpenAsync();
return (await new NpgsqlCommand(sql, con).ExecuteScalarAsync()).ToString();
}
I get the error 08P01: unsupported pkt type: 80 on opening the connection.
In this post the problem could be solved by an extra parameter in the jdbc connectionstring, but this parameter seems unavailable in a npgsql connectionstring.
How can I get some pgbouncer stats in a c# client?
EDIT:
In the meantime I tried Devart provider (Express edition), but it don't work too, because the provider commits a SELECT VERSION(); during the connect, and the pgbouncer database don't understand this statement => Exception. In pgbouncer forum I can't find a solution as well.
I can't believe that this task apparently is so rarely. I'm really surprised.
PostgreSQL has two query protocols at the wire level - the simple protocol and the extended protocol; it seems that the pgbouncer admin interface supports only the simple protocol, but Npgsql only supports the extended protocol. That unfortunately means that the two are incompatible at the moment.
This issue tracks adding support for the simple protocol to Npgsql.

Cannot connect to https://api.elephantsql.com from pg admin

has anyone success to create connection to elephantsql.org using pgadmin?
i want to try to store my database on a server and im trying to use elephantsqlcom
i want to connect to it using pg admin to make maintenance easier. i have followed this instruction : https://www.elephantsql.com/docs/pgadmin.html but keep getting this error
what should i do? thanks all
change database name from postgres to xwpgagbb similar to:
see user AND DEFAULT DATABASE are the same?..

How does ODBC pull database connection details?

I currently have a Macro which is connecting to a sybase database using ODBC. It's making the connection by running the following:
Set conX = wrkODBC.OpenConnection("Connection1", , True, strConn)
where strConn = "ODBC;DSN=Server_Name;APP=Daily Task;DB=db_name;UID=uname;PWD=pwd;"
The problem I am having is that this connection is working for some Server_Name's but not others. When it doesn't work I get a Error "3146 - ODBC--call failed".
What I don't understand is where it is pulling the server details from. So for example, when using embarcadero rapid to connect to a sybase database, it will use the sql.ini file to pull the server connection details based on the server_name.
I have checked and all the Sybase Servers I am testing are in the sql.ini file and my env variables are pointing to the correct sybase version. I've checked ODBC and it is only picking up a SQL Server driver.
Can anyone please explain how ODBC pulls the server name connection details? I don't understand why it works for some server names, but not others (FYI, I have tested the uname and pwd is rapid to make sure it is correct).
Any information would be much appreciated.
So, the issue was that I was looking at my odbc connections under control panel. I should mention that I am on windows 7. What I had to do was update my ODBC connection details here:
C:/Windows/SYSWOW64/odbcad32.exe
--This is for 32bit!
This had some connections set up which is why I could connect to some servers but not all of them.

connectionstring with userid but blank password for ado.net C#

I am not able to connect to the server say for instance from SQL Server Management Studio I am able to connect to the server 192.168.7.3 as server address using SQL Server authentication and also using the user ID as super.
But can someone tell me how to give the connectionstring so that I can use a blank password for the user "super" from the ado.net connectionstring so that I can connect to the server using SqlConnection object something like this :
SqlConnection con = new SqlConnection("server=192.168.7.3;database=test;user ID=super;password=");
I'm trying this but it's not working. What's the actual syntax to use a blank password for the server connection in sqlconnection object?
Note, this is the requirement. I know using blank password isn't recommended, but I am forced to do this.
The following ConnectionString should work. If not, the problem is elsewhere, perhaps network related.
Data Source=192.168.7.3;Initial Catalog=test;User Id=super;Password=;
Reference: SqlConnection.ConnectionString Property