2015年8月11日 星期二

Entity Framework 設定command timeout及isolationlevel

 
修改你的emdx例 MyData.edmx 下的MyData.Context.cs檔
在初始化時加入設定,如下:

 public MyDataContext()
            : base("name=MyDataContext")
{
 this.Database.CommandTimeout = 180;  //秒,語法執行timeout時間
 ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180; //這樣也可
 //isolation=readuncommitted         
 ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");

}


在SSMS 模擬LOCK狀態
begin transaction
update mytable set mycolymn =1 where myid = 1

然後執行網站上的查詢程式,會發現畫面一直在處理中

在SSMS 執行rollback還原後,網站畫面就可以顯示查詢結果了

在context建立時加入上述設定,就可避掉資料批次異動處理時造成的LOCK而無讀取。


2015年7月26日 星期日

移機掛載MDF

重裝OS WIN8,想將原來的SQL2014 資料庫利用附加方式掛載,掛載時出現以下訊息:

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

CREATE FILE encountered operating system error 5(存取被拒。) while attempting to open or create the physical file 'E:\WorkDB\SQL2014\Data\XXXXX.mdf'. (Microsoft SQL Server, Error: 5123)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=12.00.4100&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476



------------------------------

爬文查看後,開啟SSMS時得要用Administrator權限。
解法是直接關掉UAC,除了 控制台\使用者帳戶和家庭安全\使用者帳戶 變更使用者帳戶控制設定調到不通知外,還得改一下機碼才可在WIN8真正關掉UAC

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\EbableLUA 設為0 

太久沒重裝了,都忘了要先關UAC,關了他避免掉許多麻煩,但自已得要有SENSE不要開了不該開的東西啊。 

ps.一直搞不懂,登入帳號就是administrators群組了,為何開啟應用程式時,老要問我是否要以系統管理者執行呢? 

2015年4月26日 星期日

rdlc 匯出excel,不合法的 xml 字元

rdlc或rdl,在匯出excel(xlsx)後,開啟execl檔,出現『我們發現XXX.xlsx的部份內容有問題。您要我們盡可能嘗試復原嗎?如果您信任此活頁簿,請按一下【是】』。

接著點選【是】 後,就出現以下錯誤:

已取代的部分: /xl/worksheets/sheet1.xml 部分具有 XML 錯誤。  不合法的 xml 字元。 行 17,欄 441033。

測試後,原來有一個欄位的內容造成匯出的錯誤。但不解的是WHY??

這個欄位的內容如下,看起來似乎很正常,但把他COPY起來貼到記事本後,會發現設備前多了一個看似空白的空格。

脈衝電場(PEF)殺菌 設備

解出來是0x0B,在XML上這是個不合法的字元。

所以先把這個看似空白的字元刪除,匯出後開啟EXCEL就OK了。

2015年3月5日 星期四

已經開啟一個與這個 Command 相關的 DataReader,必須先將它關閉

.net 執行SQL指令時,出現以下錯誤。

已經開啟一個與這個 Command 相關的 DataReader,必須先將它關閉。

在web.config connectionstring 加入 "MultipleActiveResultSets=True" 後,顯示出了正確的錯誤原因,原來是SQL SELECT 中有相同的欄位名稱重覆了二次。

2015年2月11日 星期三

MSOLAP 目標電腦拒絕連線

一個legacy system,vb2003+sql2000+olap2000+dts2000+rs2000,用了11年了。

中間曾因客戶不想花錢升級sql2005,因為OLAP和DTS要打掉重做,客戶覺得為什麼要花錢重做,為什麼不能直接升級上去就好...BLA BLA BLA.....反正就一直撐著。


最近有個以他的OLAP2000當資料來源的系統先升級了,OS換成WINDOWS 2008R2+SQL2005 64bit,原本是WINDOWS2003R2+SQL 2005 32bit,升級後,在SQL 2005 64BIT上建立OLAP 的LINKED SERVER時,出現了以下的錯誤,
MSOLAP 目標電腦拒絕連線

查到這篇KB,真是殘念啊,OLAP2000只能在SQL SERVER2005 32BIT上才能建立LINKED SERVER。

After you install a 64-bit instance of SQL Server 2005 Analysis Services, only the 64-bit version of the Microsoft OLE DB Provider for Analysis Services 9.0 provider is available. The 64-bit version of the SQL Server service can use this provider to connect to 64-bit instances of SQL Server 2005 Analysis Services and to 32-bit instances of SQL Server 2005 Analysis Services. However, the 64-bit version of the SQL Server service cannot use this provider to connect to SQL Server 2000 Analysis Services.

After you install a 32-bit instance of SQL Server 2005 Analysis Services, the 32-bit version of the Microsoft OLE DB Provider for Analysis Services 9.0 provider is available. If you are running the 32-bit version of the SQL Server service, the SQL Server service can use this provider to connect to SQL Server 2000 Analysis Services. 

改裝了SQL2005 32BIT就可正常連線到OLAP2000了。

最近花了很多時間在搞這種舊系統,真是累!

2015年2月10日 星期二

SQL2014 SHORTCUT RECOVERY

安裝了SQL Server2014後,原本的捷徑紛紛失效
例如CTRL+R,可以顯示或隱藏QUERY RESULT

機器上原本安裝的是SQL 2012,結果也在安裝完SQL2014後,捷徑也一起失效了。

查了半天,有人說在Tools>>Options>>Environment>>Keyboard Reset一下keyboard的設定就回復正常了。

如法泡製...咦........真的就好了。

附上SHORTCUT說明

https://msdn.microsoft.com/zh-tw/library/ms174205.aspx

2014年11月9日 星期日

dynamic decalre cursor...does not exist.

同事寫了一段SQL在SQL2000執行正常,但在SQL2008R2無法執行
SQL中是動態組一段declare cursor的語法
模擬了一下SQL大概如下

declare @sql nvarchar(4000),@c1 nvarchar(10),@c2 int
set @sql = N'declare cur cursor for select ''col1'' as col1 ,1 as col2'
exec sp_executesql @sql
open cur
fetch next from cur into @c1,@c2
while @@FETCH_STATUS = 0
begin
 print @c1
 fetch next from cur into @c1,@c2
end
close cur
deallocate cur


在SQL2000執行正常,會print出 'col1'

但在SQL2008R2上,回傳了以下的錯誤
Msg 16916, Level 16, State 1, Line 3
A cursor with the name 'cur' does not exist.
Msg 16916, Level 16, State 1, Line 5
A cursor with the name 'cur' does not exist.
Msg 16916, Level 16, State 1, Line 11
A cursor with the name 'cur' does not exist.
Msg 16916, Level 16, State 1, Line 12
A cursor with the name 'cur' does not exist. 


後來發現,在SQL2008R2另外幾個DB也可正常執行,就只有某個DB不行

查看了該DB的屬性,最後在option 的設定下有關Cursor的設定,有參數值Default Cursor = LOCAL,改成了GLOBAL後,就可利用dynamical sql宣告CURSOR了

VS CODE離線安裝套件方式-續

去年 vscode離線安裝 powershell nupkg 今年在一台無外網的 windwos 2025上安裝時遇到了powershell版本一直讀取到了5.1的版本,鬼打牆了一下午,在VM還原重測測了好幾回,應該是可行了。 將下載到的免安裝powershell 解壓縮到...