Alexander Ka
Alexander Ka

Reputation: 299

Can't connect to Azure postgres with psycopg. The server name you tried cannot be found

I want ot connect externally via psycopg2 to Azure postgresql. I have created a server with postgresql db on it. The problem is that when I try to create a connection the error comes up saying that 'psycopg2.OperationalError: FATAL: The server name you tried cannot be found. Please use the correct name and retry. Please check your server name lfsserverlv.'

import psycopg2

conn = psycopg2.connect(
    host='lfsserverlv.database.windows.net',
    dbname='lfsdb',
    user='adminlfs@lfsserverlv',
    password='some_password',
    sslmode='require'
)

The server name is on the screenshot below (Sorry for Russian in it) There should be something else I pobably don't know on connections to Azure. Any help would be greatly appreciated

enter image description here

Upvotes: 1

Views: 2110

Answers (1)

CHEEKATLAPRADEEP
CHEEKATLAPRADEEP

Reputation: 12768

Make sure you have passed the correct server name.

Get the connection information needed to connect to the Azure Database for PostgreSQL. You need the fully qualified server name and login credentials.

  1. Log in to the Azure portal.
  2. From the left-hand menu in Azure portal, click All resources, and then search for the server you have created (such as chepra).
  3. Click the server name.
  4. From the server's Overview panel, make a note of the Server name and Server admin login name. If you forget your password, you can also reset the password from this panel.

enter image description here

By using the above connection information, I'm able to connect Azure Database for PostgreSQL using python as follows:

enter image description here

For more details, refer "Connect Azure Database for PostgreSQL using Python".

Hope this helps.

Upvotes: 1

Related Questions