星期三, 5月 17, 2017

刪除重複的資料

在各分公司資料同步的過程,為了避免資料出問題,都沒有設定 PK,偶而就會造成資料重複傳送的問題,偶而就會需要刪除重複
SELECT DISTINCT * FROM [TableName]
通常我會很搞剛的先放到另一個 Table 去,然後清空資料再到回來

SELECT DISTINCT * INTO [Temp_TableName] FROM [TableName]
DELETE FROM [TableName]
INSERT INTO [TableName] SELECT * FROM [Temp_TableName]
DROP TABLE [Temp_TableName]

就這樣完成!!

星期四, 5月 11, 2017

不登入也能關機,遠端重開機

今天遇到要連到使用者的電腦時候,怎麼連線都是登入後就斷線,只好想辦法重開機看看,可是不能登入怎麼重開機呢?

在 Google 搜尋了一下發現還真的有

先打開命令提示字元,

然後輸入 net use \\PCName /user:loginaccount

接著輸入密碼,就可以登入成功了。

接著就是使用 shutdown 來進行重開機了,

shutdown -m \\\\PCName -f -r -t 10

還真的就成功了。

星期一, 5月 08, 2017

SQL Agent Job Failed: This error occurs when there is a cryptographic error.

從 DTS 轉移到 SSIS 的排程在執行時發生錯誤,錯誤畫面如下,看起來就像是沒有權限去解密執行,

Description: Failed to decrypt protected XML node "PassWord" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available.  End Error  Error: 2017-05-08 02:00:00.91     Code: 0xC0016016     Source:       Description: Failed to decrypt protected XML node "PassWord" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available.  End Error  Error: 2017-05-08 02:00:00.91     Code: 0xC0016016     Source:       Description: Failed to decrypt protected XML node "DTS:Password" with error 0x8009000B "Key not valid for use in specified state.". You may not be authorized to access this information. This error occurs when there is a cryptographic error. Verify that the correct key is available.  End Error  Error: 2017-05-08 02:00:01.25     Code: 0xC002F304     


後來應該是我有編輯過,RUN AS 要改成我用來編輯的帳號來執行,因為預設會用該帳號去加密,所以這邊只要設定 Credentials 裡面先建立帳號,再到 SQL Server Agent 設定 Proxy


接著在 Run as 就可以選擇該帳號,執行就可以成功了。


Convert DTS from SQL Server 2000 to SQL Server 2008 R2 SSIS

當 SQL Server 從 2000 升級之後,就沒有 DTS 可以使用了,這時候只能將 DTS 轉成 SSIS,
需要安裝 Microsoft SQL Server 2000 DTS Designer Components 跟 Microsoft SQL Server 2005 Backward Compatibility Components 64 bit 就可以使用 DTS 封裝移轉精靈。

在 SQL Server 2008 Management Studio 展開 Management -> Legacy -> Data Transformation Service,按右鍵選擇 Migration Wizard

接下來就是選擇來源,這邊我選擇舊的 SQL Server 2000
 匯入到新的 SQL Server 2008
 選擇要轉換匯入成 SSIS 的 DTS
 找個地方來放 Log 的
 最後確認,沒問題點選 Finish 後開始轉換
接下來連到 Integration Service 就可以看到匯入的 SSIS 了