共用方式為


建立變數值檔案 (AccessToSQL)

變數值檔案是 XML 檔案,包含命令的參數值 (例如來源或目的地伺服器名稱),經常在伺服器移轉之間變更。 發生大量資料庫移轉時,命令列上會使用 -v 切換控制,在主要指令檔參考儲存每個來源伺服器值來建立多個變數檔案。 這個作法有助於在幾個指令檔中維護靜態值,以及多個變數檔案中的變數值。

注意

  • 變數名稱前綴及尾綴會加上 $ (元) 符號。 如未在變數值檔案指派變數值,在剖析指令檔期間會產生錯誤,導致主控台執行處理序停止。
  • $ 的逸出字元為 $$。 如果參數的變數值或靜態值包含 $ (元) 符號,則必須指定 $$ 來將其視為字元,而不是變數。
  • 為了維護性,可在 'variable-group' 元素內宣告變數,以邏輯分隔使用者定義變數。 此元素的使用並非強制。

範例:

範例 1:

<!--Sample of variable value file commands-->  
  
<variables>  
  
  <variable-group name="ProjectSpecs">  
  
    <variable name="$type$" value="MyProject"/>  
  
    <variable name="$project_folder$" value=".\$project_name$"/>  
  
    <variable name="$project_name$" value="$type$ConsoleProject"/>  
  
    <variable name="$project_overwrite$" value="true"/>  
  
    <variable name="$project_type$" value="sql-server-2008"/>  
  
  </variable-group>  
  
</variables>  

範例 2:

<!--Sample of variable value file commands-->  
  
<variables>  
  
  <variable-group name="SQLServerParams">  
  
    <variable-group name="SqlServerConnectionParams">  
  
      <variable name="$TargetServerName$" value="xxx"/>  
  
      <variable name="$TargetDB$" value="xxx"/>  
  
      <variable name="$TargetUserName$" value="xxx"/>  
  
      <variable name="$TargetPassword$" value="xxx"/>  
  
      <variable name="$TargetIsTrusted$" value="xxx"/>  
  
      <variable name="$TrustedConnection$" value="xxx"/>  
  
    </variable-group>  
  
    <variable-group name="SqlServerObjectParams">  
  
      <variable name="$ObjectName1$" value="TestTable1"/>  
  
      <variable name="$ObjectName2$" value="TestProc1"/>  
  
    </variable-group>  
  
  </variable-group>  
  
</variables>  

變數值檔案驗證

使用者可以輕鬆地根據「Schemas」資料夾中所提供的結構描述定義檔 ConsoleScriptVariablesSchema.xsd 來驗證其變數值檔案。

後續步驟

操作主控台的下個步驟是建立伺服器連線檔案 (AccessToSQL)

另請參閱

建立伺服器連線檔案 (Access)