星期四, 7月 13, 2017

VB6.0 專案開啟出現"無法載入mscomctl.ocx"

安裝好新的開發環境後,開啟 VB6 的專案竟然出現"無法載入 mscomctl.ocx" 的錯誤,
奇怪,我連 SP6 都已經安裝了呀,怎麼會有這種錯誤呢?

後來找到了一個 SP6 的安全彙總更新 ( 什麼鬼啦,都到SP6了還有安全問題唷 )


安裝之後就可以順利開啟專案了


參考:http://heryla.tian.yam.com/posts/56195148 

星期二, 6月 27, 2017

SQL Trigger 來紀錄哪些欄位被修改了


SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER TRIGGER [dbo].[TR_TestTable_Modify] on [dbo].[TestTable]

   AFTER UPDATE

AS

BEGIN

  DECLARE @DBTableID int;

  DECLARE @Columnid int;

  DECLARE @ColumnCount int;

  DECLARE @i int;

  DECLARE @ColumnName varchar(20);

  DECLARE @SQL varchar(4000);

  DECLARE @LogTime datetime;

  DECLARE @program nvarchar(200)





  SELECT @DBTableID=id from sysobjects where name='TestTable'

  SELECT @ColumnCount=MAX(column_id) FROM sys.columns WHERE [object_id]=@DBTableID

  SELECT @program=program_name from sys.dm_exec_sessions where session_id=@@SPID



  select * into #inserted from inserted;

  select * into #deleted from deleted;



  SET @i = 0

  SET @LogTime=GETDATE()



  WHILE @i < @ColumnCount

  BEGIN

   SET @i = @i+1



   SELECT @ColumnName=name FROM sys.columns WHERE [object_id]=@DBTableID AND column_id=@i

   SET @SQL = 'INSERT INTO LogTable SELECT a.invno,''‘TestTable'',''' + @ColumnName + ''',a.' + @ColumnName + ',b.'+ @ColumnName + ',''' + convert(varchar(30), @LogTime,121) + ''',''' + @program + ''' FROM #deleted a,#inserted b WHERE a.PK=b.PK AND a.' + @ColumnName + ' <> b.' + @ColumnName

   EXEC (@SQL)

  END



  drop table #inserted;

  drop table #deleted;



END

GO

C# DateTime 相減

每次用到都要去 Google,這次決定把他記下來

當兩個 DateTime 要相加減時就需要用到 TimeSpan

DateTime begDate = DateTime.Now;
TimeSpan ts = DateTime.Now - begDate;
string diff = ts.Minutes.ToString() + "分" + ts.Second.ToString() + "秒";

星期一, 6月 05, 2017

Transaction Log 備份失敗 - 因為沒有目前的資料庫備份

昨天突然 Transaction Log 備份出現了錯誤:因為沒有目前的資料庫備份。 BACKUP LOG 正在異常結束。

只好求助 Google 了,才知道原來是當時的資料庫的復原模式重簡單改成完整之後都沒有進行過完整備份或差異備份,所以 Transaction Log 沒有一個紀錄點,才會有這個錯誤發生。



Reference: https://dotblogs.com.tw/terrychuang/2013/08/28/115722

星期三, 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 了


星期三, 4月 26, 2017

X220 升級 USB 3.0, 換鍵盤, 藍芽 4.0

X220 真的是一台好機器,可惜年代久遠,當時只有 i7 的機器有支援一個 USB 3.0,我手上這台 i5 就只能靠擴充卡去達到這目的

當然,當年也還沒有藍芽 4.0,可是現在的藍芽滑鼠都是 4.0 的,沒有向下支援,所以也要換掉。

 既然都要拆開了,就順便把鍵盤也換掉吧!
要換鍵盤跟開 C 蓋就只要卸除七個螺絲
藍芽的位置就在這裡,鬆開螺絲換上 4.0 的就可了。
Windows 10 開機就抓到了,什麼都不用安裝就可以使用,
換上新鍵盤,整個就乾淨多了。

星期四, 4月 13, 2017

SQLite Administrator

SQLite 是一個免費又好用的檔案型資料庫,第一次認識他是在上 Android 開發的課程,現在要開發 Windows Mobile 6.5 上面的程式時,就想到使用 SQLite 來當作資料庫紀錄,避免無線網路連線問題時,有資料的遺失。

既然是資料庫,就需要有一個管理介面了,網路上找到蠻好用的 SQLite Administrator 軟體

官網:http://sqliteadmin.orbmu2k.de/
下載:http://download.orbmu2k.de/download.php?id=19

整個介面就很簡單,而且還有正體中文可以選擇,建立好資料庫之後,新增 Table 也可以發現有很多欄位的設定可以使用,建立好 Table 後就可以放到 Mobile Device 中給程式使用了。