0

So we use osql to run in stored procedures as part of our build process. We use a project with an sp folder that gets published with applications as part of a build pack.

I used Visual Studio to create this project structure and created the sql scripts to run in the procs.

Visual Studio saved the files with UTF8 formatting (by default). osql when running in the scripts complained about every single script having a syntax error on line 1 i.e.

> Incorrect syntax near 'ยด'.     1> 2> Msg 102, Level 15, State 1,
> Server GBEPIAP-SQL01, Line 1

Rather baffling.

Anyway; to fix the issue, the sql scripts could be saved with Unicode Codepage 1200 (File -> Advanced Save Options)

et voila - problem gone

Now that's left me with an even bigger problem; I have over 200 proc scripts that I need to open, change encoding and save with the new encoding.

Can any powershell guru do me up a quick script to change the encoding of every file in a folder to Unicode Codepage 1200? Would be doing me a favour while also saving time.

Dave Lawrence
  • 3,843
  • 2
  • 21
  • 35
  • 1
    OSQL is really really old - you should try to use `sqlcmd` instead, which is much more recent and might handle encodings better โ€“ marc_s Apr 29 '13 at 11:21
  • Valid enough comment. I can make a suggestion to the build team but that's outside my remit. โ€“ Dave Lawrence Apr 29 '13 at 11:26

1 Answers1

1

In the end I used the approach documented here

Save all files in Visual Studio project as UTF-8

But instead of UTF8; I specified Unicode.

foreach (var f in new DirectoryInfo(@"...").GetFiles("*.sql", SearchOption.AllDirectories)) {
  string s = File.ReadAllText(f.FullName);
  File.WriteAllText (f.FullName, s, Encoding.Unicode);
}
Community
  • 1
  • 1
Dave Lawrence
  • 3,843
  • 2
  • 21
  • 35