2014-01-31 69 views
5

最近我有我的笔记本电脑SSMS 2008年重新安装默认编码在SQL Server Management Studio中

当我点击“新建查询...”,我现在提示您选择文件的编码,这是我从来没有要求做之前

我在选项的文本编辑器部分相关的SQL againt“SQL查询编辑器与编码”并重新启动SSMS

我能做些什么来与编码相关联的我不t想每次选择新查询或打开现有的sql文件时选择

回答

1

我是一个这样一个白痴 - 我改变了关联到“SQL查询编辑器”,它现在一切正常

“与编码”位应该真的让我失望!

+2

你能解释一下你的意思吗?你改变的设置在哪里? – CowboyBebop

+0

试过这个,没有快乐 – Roger

6

按照Fakher Halim在Microsoft Connect上发布的解决方法。

我有同样的问题。 Git不会显示历史记录 (除了“Binary files a/x.sql和b/x.sql不同)”之外,所以我点击 Tools => Options => Environments => International Settings。将 语言从“英语”到“同的Microsoft Windows”现在GIT DIFF 工作得很好! - 报告版本差异通常

+2

这对我来说没有什么不同。 – Liam

+0

值得指出的是,我正在使用英国英语Windows,因此SQL Server中的“英语”是一种不同的语言。 –

2

基于其他地方给出的建议(https://connect.microsoft.com/SQLServer/feedback/details/288677/unicode-defaults-on-ssms-save)我砍死了一个“命令脚本”尝试使用BOM将“默认编码”更改为UTF-8该脚本通过在SQL Server的Program Files树的SQLFile.sql文件中编写一个UTF-8 w/BOM模板来工作,它曾经工作过一次我的机器,但这并不意味着它是无bug或100%安全的N风险!

根据该线程“微软的”回应:

默认的文件的保存方式是由位于C主模板文件SQLFile.sql的方式确定:\ Program Files文件\ Microsoft SQL Server的\ 90个\工具\ BINN \ VSShell \ Common7 \ IDE \ sqlworkbenchprojectitems \ SQL。如果使用ANSI编码保存此文件,则后续的新查询会话将使用此编码。

请注意,我的机器上,我发现在不同的路径中的模板,所以我写的剧本找到任何下的文件或者程序文件匹配这个名字。这似乎是一个愚蠢的名字,错误的碰撞应该是罕见的。

如果不传递任何参数(或者它所期望的任何其他参数),那么它应该执行一个空运行。确保先运行它没有管理权限。它至少会找到任何适用的文件,然后您可以决定是否继续处理脚本或自己修改文件。

要运行真实的脚本,然后传递“force”的第一个参数。这是危险的部分。注意谨慎。要运行脚本完成而不暂停用户输入,则传递第二个参数“dontpause”(这可以通过空的第一个参数传递,以便在空运行期间跳过暂停)。

我选择UTF-8是因为它与7位ASCII兼容,它支持绝大多数语言和字符,你将永远关注脚本,它非常有效地存储西文和源代码,它的源代码控制/文本补丁友好。脚本底部的模板包含一个字节顺序标记(BOM),用于向编辑者表明它不是ISO-8859-1或其他一些不兼容的默认8位编码。确保它在复制/粘贴时不会丢失。将实际批处理脚本保存为ASCII(或兼容;不含BOM!)。命令处理器在UTF-8 BOM上扼流圈。

@echo off 
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION || exit /b 1 

if "x%1" == "xforce" (
    echo Force enable. Danger Will Robinson! This means that I'm going to 
    echo attempt to move files and write a new file to replace them. This 
    echo is potentially destructive if there are any bugs in this script. 
    echo In particular, if there are any unrelated files with the name 
    echo sqlfile.sql under your Program Files directories then they'll be 
    echo corrupted. 
    echo. 
    echo This script is going to require elevated privileges to write to 
    echo Program Files. Execute the Command Prompt application as an 
    echo administrator to proceed ^(should be harmless to try without 
    echo elevation first^). 
    echo. 
    echo I RECOMMEND YOU _DO NOT_ RUN THIS SCRIPT FROM WINDOWS EXPLORER 
    echo BECAUSE YOU MAY HAVE A HARDER TIME READING THE OUTPUT. Start a 
    echo Command Prompt and run it there. 
    echo. 

    if not "x%2" == "xdontpause" (
     echo Now is a good time to Ctrl+C ^(and Y^). 
     pause 
    ) 
) else (
    echo Dry-run enabled. Pass a lone argument of "force" to go for real. 1>&2 
    echo Be careful running the script several times. Your template backup 
    echo will be overwritten and lost. 
) 

set paths="C:\Program Files (x86)\SQLFile.sql" "C:\Program Files\SQLFile.sql" 

for /f "tokens=*" %%f in ('dir /a /b /s %paths% 2^>NUL') do @(
    echo. 
    echo Found: %%f 

    if "x%1" == "xforce" (
     echo Moving to: %%f.orig 
     echo. 
     echo If you ^(or anything else^) has made any changes to your template 
     echo then you should be able to recover your template from the backup 
     echo file above ^(not yet, once you continue^) ^(alternatively, 
     echo recover the template from the source file now^). 

     if not "x%2" == "xdontpause" (
      pause 
     ) 

     move "%%f" "%%f.orig" || exit /b 1 
    ) 

    echo. 
    echo Writing a standard UTF-8 template with byte-order mark ^(BOM^). 
    echo Feel free to open this file up afterward and manually set the 
    echo encoding preferred. You can also replace it with your own 
    echo template text. 

    if not "x%2" == "xdontpause" (
     pause 
    ) 

    set ok=0 

    rem Read in myself, look for the __BEGIN__ marker and write 
    rem subsequent lines to the file. 
    for /f "tokens=*" %%g in (%~dpf0) do @(
     if !ok! == 1 (
      if "x%1" == "xforce" (
       if "x%%g" == "x." (
        echo. 
        echo.>>"%%f"|| exit /b 1 
       ) else (
        echo %%g 
        echo %%g>>"%%f"|| exit /b 1 
       ) 
      ) 
     ) else (
      if "%%g" == "__BEGIN__" (
       echo. 
       echo Found marker. Starting write on next ^(non-empty^) line... 1>&2 
       echo. 
       set ok=1 
      ) 
     ) 
    ) 
) 

exit /b 0 

Below is the SQL template. Lines containing only a dot (.) represent 
blank lines. Actual blank lines will be lost. 

__BEGIN__ 
BEGIN TRANSACTION; 
. 
SET XACT_ABORT ON; 
. 
. 
. 
ROLLBACK; 
--COMMIT; 
1

在SQL Server Management Studio中,选择工具/选项,然后展开“文本编辑器”,并添加扩展名“SQL”并将其映射到“SQL查询编辑器”。

解决方案的工作,如果你是ASCII字符的工作。如果sql包含需要显式编码的字符(由SQL编辑器确定),那么您将必须选择一种编码。在SQL编辑器和其他编辑器(NotePad ++)中创建文件,然后在其他编辑器中编辑这些文件时,问题就会起作用。 NotePad ++保存没有标题的文件,并可以猜测编码。另一方面,SQL编辑器在使用特定字符时总是需要编码头。

+0

什么,为什么?这有什么帮助? – Liam

+0

OP麦克回答了他自己的问题 - 这显示了迈克指出的选项可以找到的地方。 – LeeLep

+0

如果您使用ASCII字符,则该解决方案可以正常工作。如果sql包含需要显式编码的字符(由SQL编辑器确定),那么您将必须选择一种编码。在SQL编辑器和其他编辑器(NotePad ++)中创建文件,然后在其他编辑器中编辑这些文件时,问题就会起作用。 NotePad ++保存没有标题的文件,并可以猜测编码。另一方面,SQL编辑器在使用特定字符时总是需要编码头。 – LeeLep

2

先前的答案建议使用工具→选项→环境→国际设置,但该选项不存在于SSMS 17.2中。

取而代之,您可以转到文件→另存为...,单击“保存”按钮上的箭头,然后选择“使用编码保存”。

相关问题