108

I am trying to open an SQL data connection using a PowerShell script and my password contains a $ sign:

$cn = new-object system.data.SqlClient.SqlConnection("Data Source=DBNAME;Initial Catalog=Catagory;User ID=User;Password=pass$word;")

When I try to open a connection it says:

Login failed

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Murtaza Mandvi
  • 10,708
  • 23
  • 74
  • 109

1 Answers1

197

Escape it by using backtick (`) as an escape character for the dollar sign ($).

Also, try to enclose the statement in single-quotes instead of the double-quotes you are using now.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shankar R10N
  • 4,926
  • 1
  • 21
  • 24