What is a connection string? Explain its parts.

BeginnerConceptDatabase connections in apps
Answer

Short answer

A connection string is a single line of text that tells an application how to connect to a database: the driver/protocol, host, port, database name, username/password and extra options like TLS.

Example broken down

postgresql://orders_app:[email protected]:5432/orders?sslmode=require
   driver      user     pass         host        port  database   options

Formats per stack

Stack Example
Java JDBC jdbc:postgresql://db.prod.internal:5432/orders + separate user/password
MySQL JDBC jdbc:mysql://db:3306/shop?useSSL=true&serverTimezone=UTC
Node / Python URL postgresql://user:pass@db:5432/orders
.NET Host=db;Port=5432;Database=orders;Username=app;Password=***;SSL Mode=Require
MongoDB mongodb://app:pass@m1:27017,m2:27017/orders?replicaSet=rs0&authSource=admin

Gotcha

Special characters in passwords (@ : / # ?) must be URL-encoded in URL-style strings (@ → %40), or the parser splits the string in the wrong place.

What to say in the interview

"A connection string encodes driver, host, port, database, credentials and options like sslmode. The format differs by language — JDBC URLs for Java, URLs for Node and Python, key=value for .NET — and we always inject it from a secret, never hard-code it."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Connecting apps to databases

More on Database connections in apps