I am using a batch file to run sqlcmd (Sql server 2008), which in turn run various sql scripts. The sql scripts i开发者_如何学Pythonnsert Asian and English characters into a database. The issue I have is that the Asian characters come out garbled (while the English come out okay.) When I manually run the chinese-character scripts they runs fine. Does anyone know how to get around this issue?
This is probably too late to solve your problem, but I encountered a similar issue. The solution for me was to provide an explicit code page to sqlcmd via the '-f' command line parameter:
sqlcmd ... -i input.sql -f 65001
65001 is the code page for UTF-8. You will need to make sure the file is actually saved with this code page, which you can do in Visual Studio:
Try this:
1. Open your file in Visual Studio.
2. From the File menu, choose Advanced Save Options.
3. Select this encoding:
Unicode (UTF-8 without signature) – Codepage 65001
4. Save the file.
(Quoted from a blog post comment which gave me enough info to piece together the solution.)
How exactly are you using the files? If you currently do
sqlcmd ... < input.sql
then consider either changing the font of the console window to a TrueType font or change that into
sqlcmd ... -i input.sql
I guess the characters get garbled upon redirection in a console that only support the OEM character set.
精彩评论