none
SQL connection string failed for $ password RRS feed

  • Question

  • Hi Team,

    I am not able to connect to SQL DB when password contains $ symbol. Please help me to open connection for this scenenrio.

    $sqlconstr = "Data Source=Server1;Initial Catalog=DB;User ID=User;pwd='$$XXXXX0';"
    $sqlconn = New-Object system.Data.SqlClient.SqlConnection
    $sqlconn.connectionstring = $sqlconstr
    $sqlconn.open()

    Tuesday, February 3, 2015 11:57 AM

Answers

All replies

  • Because the entire string is a double-quoted string, it's going to try to interpret the $ as a powershell operator. 

    You can force it to interpret the $s as literal characters by escaping them with the backtick (`)

    $sqlconstr = "Data Source=Server1;Initial Catalog=DB;User ID=User;pwd='`$`$XXXXX0';"

    See:

    Get-Help about_Quoting_Rules


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "


    Tuesday, February 3, 2015 12:21 PM
    Moderator
  • Thanks I tried below string & it worked
    $sqlconstr = 'Data Source=Server1;Initial Catalog=DB;User ID=User;pwd=$$XXXXX0;'
    Tuesday, February 3, 2015 1:50 PM