URI connection string

Additional notes on constructing your database URI.

Database URI connection strings certain characters should be avoided or properly escaped in the username and password components. These characters can cause issues because they have special meanings in the context of a URI or the connection string format itself.

Refer to our database-specific guides for additional URI construction notes.

Special Characters to Avoid or Escape:

  1. Colon (:) - Used to separate the username from the password.
  2. Slash (/) - Used to separate the password from the host/address and to denote paths.
  3. At sign (@) - Used to separate the credentials from the host/address.
  4. Question mark (?) - Used to start the query parameters.
  5. Ampersand (&) - Used to separate query parameters.
  6. Equal sign (=) - Used within query parameters to assign values.
  7. Space ( ``) - Spaces can cause issues if not URL-encoded.
  8. Plus sign (+) - May be interpreted as a space in URLs.
  9. Percent sign (%) - Used for percent-encoding special characters.
  10. Single quote (') - Used to delimit strings; must be percent-encoded.
  11. Double quote (") - Used to delimit strings; must be percent-encoded.
  12. Hash (#) - Used to indicate a URL fragment.

How to Handle Special Characters:

To include these characters in your username or password, you should URL-encode them. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits corresponding to the character's ASCII value. For example, a colon (:) is encoded as %3A, and an at sign (@) is encoded as %40.

Example:

If your password is p@ss:word, it should be encoded as p%40ss%3Aword in the URI.

Special Characters and Their Percent-Encoding:

  1. Colon (:) - %3A
  2. Slash (/) - %2F
  3. At sign (@) - %40
  4. Question mark (?) - %3F
  5. Ampersand (&) - %26
  6. Equal sign (=) - %3D
  7. Space ( ``) - %20 or + (though %20 is more universally accepted in this context)
  8. Plus sign (+) - %2B
  9. Percent sign (%) - %25 (used to start the percent-encoding itself)
  10. Single quote (') - %27
  11. Double quote (") - %22
  12. Hash (#) - %23