question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Database connection not allowing back slash or maybe other of the special characters

See original GitHub issue

Bug description

I already generated my prisma client and my application was running fine, but now the DB user password changed and it has a lot of special characters, so I escaped them using the corresponding percent-encoding value like this:

(+): %2B (😃: %3A (^): %5E (): %5C note: back slash is not showing inside the parenthesis but is there ($): %24

So my DATABASE_URL looks something like this: DATABASE_URL="sqlserver://{ipaddress}:1433;database={dbname};user={dbuser};password=AbCdE%2B%3A%5E%5C%24;trusServerCertificate=true;encrypt=DANGER_PLAINTEXT"

Now when I run my application using the updated .env file with the DATABASE_URL, I’m getting the following error: (node:28652) UnhandledPromiseRejectionWarning: Error: Error creating a database connection. (Authentication failed for user dbuser).

Am I doing anything wrong? Please advice.

How to reproduce

  1. After client was generated successfully with other password
  2. Change the db user password to a string that contains those characters mentioned in the Bug description
  3. Update the password in the .env file
  4. Run the application and see the reported error

Expected behavior

The connection should be successful even if the password has special characters, since they were escaped in the DATABASE_URL.

Prisma information

Prisma schema not releventa other than possibly the initial part:

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native"]
}

datasource db {
  provider = "sqlserver"
  url      = env("DATABASE_URL")
}

Environment & setup

  • OS: Windows 10
  • Database: PostgreSQL
  • Node.js version: V14.16.0

Prisma Version

prisma                  : 3.5.0
@prisma/client          : 3.5.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules\@prisma\engines\introspection-engine-windows.exe)       
Format Binary           : prisma-fmt 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 78a5df6def6943431f4c022e1428dbc3e833cf8e
Studio                  : 0.439.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dmateus-patracommented, Jan 20, 2022

@janpio Your comment helped me and I found that for MS SQL Server the solution is to enclose each special character within braces {}. This worked for me. I think it would be good to include that detail in the documentation for MS SQL Server users, since you already have the escaping definition for other database engines. Thank you!

1reaction
janpiocommented, Jan 20, 2022

(We are going to rename that label soon, it just means that we have no looked at the issue yet to confirm that is has enough information to reproduce and someone needs to do that and engage further - sorry.)

The note in the docs only refers to PostgreSQL and MySQL, I do not know how to escape in the same way for SQL Server.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle a query with special characters / (forward slash ...
The trick is to double escape ONLY the backslash; for string escapes only a single escape is needed. For example. The single quote...
Read more >
Errors using special characters in Access databases - Office
Lists the special characters to avoid using when you work with the database object names or the field names in all versions of...
Read more >
Connection string throws a SqlConnection Error [closed]
The backslash character ( \ ) is used as an escape character, so it thinks your string includes \A , which is apparently...
Read more >
Some ODBC Applications May Not Be Able to Handle Special ...
When using ODBC, it is important to be aware that operating system identifiers (table names, column names, and so on) allow special characters...
Read more >
Handling Special Characters - Oracle Help Center
B Handling Special Characters · To escape ! (exclamation mark), use a single quotation mark around the password or use the back slash...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found