Issue SQL Query with Localized String through PowerShell

15 pts.
Tags:
Database programming
Localized String
Microsoft Access
PowerShell
Scripting
SQL
SQL Query
Windows PowerShell
Windows scripting
Hello, I am attempting to execute a an SQL query through PowerShell against an MS Access database. My query works 99% of the time, but occasionally a localized string will cause an error beacuse it contains a single quote (') somewhere within the localized string. You can look at the following example to get a better idea of what I am talking about: SELECT TermNo, File, Context FROM ExceptionFC WHERE TermNo = 1 AND File = '\frContentfr_localized_content.xml' AND Context = '(le second niveau), lequel doit accéder aux ressources d'un serveur de base de données ou d'un partage réseau (le troisième niveau). Le jeton de sécurité principal utilisé entre le navigateur et le s' In most languages I could add slashes to this string to escape out the single quotes (') in the string. But I don's seem to be able to do that in PowerShell. Is there a way I can execute this query within PowerShell and receive an accurate response back from the database? Thank you.

Answer Wiki

Thanks. We'll let you know when a new response is added.

I haven’t used powershell much. Does it have the option to do a replace on the string value?If it does replace the single quote with two single quotes. This will tell the jet engine to treat it as a single single quote.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Bgsullivan
    Yeah, it took me a while to figure it out, but it does require the use of double encoding. The following will work for anyone else who stumbles across this issue in the future: [STRING VARIABLE].Replace("'", "`'`'"). So an example would be: $unencodedString = "Bl'ah Bl'ah Bl'ah Bl'ah Bl'ah" $encodedString = $unencodedString.Replace("'", "`'`'") The result would be: Bl`'`'ah Bl`'`'ah Bl`'`'ah Bl`'`'ah Bl`'`'ah
    15 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following