2011年3月23日 星期三

災難

用virtualbox安裝一台32 bit windows 7 professional......天啊......零星災難一堆....
新的OS安裝容易但設定卻是很折騰人啊.

首先是virtualbox的網卡設定,預設安裝後啟動windows 7, 一切看來正常,系統開始做windows update, 等一切就緒後, 想要安裝其他的軟體...突然發現無法連結本機.
怪怪, virtual machine不是預設應該就能找得到母體機器的嗎???
花了幾天的時間查看,很好奇virtualbox內的ip為何是10.x.x.x的網段,一時沒細想,也沒想到要解決,最後是利用 建立共用資料夾的方式先解決. 我還在想,這更怪, 母體機器找不到,但設成共用資料夾是可以連結得到?? 一堆問號
FINALLY,終於找到解答, 要設二張網卡,一張設NAT,一張設本機網卡, 然後在母體機器的網卡開啟共用...

然後安裝IIS 7, 把網站部署上去,結果出現這個錯
這個設定區段不能在這個路徑中使用。當區段在父層級被鎖定時就會發生這種情況。鎖定可能是預設 (overrideModeDefault="Deny"),或是由位置標記使用 overrideMode="Deny" 或繼承的 allowOverride="false" 明確設定。

結果是預設安裝IIS勾選時,有一項 應用程式開發功能下的選項也要勾選安裝..
麻煩....如果不了,就全勾吧..

然後接著出現


HTTP 錯誤 500.21 - Internal Server Error
處理常式 "PageHandlerFactory-Integrated" 的模組清單中有錯誤的模組 "ManagedPipelineHandler"


google說,要重新C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe –i

 哇咧,目錄下根本沒有 aspnet_regiis.exe –i
 
所以還是要按正常方式安裝一次Net Framework 4.0....
 
搞定.... 

CKEditor p tag

繼上次借用Bugnet的htmleditor provider放在內部QA專案後,同事反應,為什麼RDLC報表跑出來這個問題說明內的說明文字每一行都空那麼大啊....很醜耶...

想想也是,挺佔空間的. 於是查了一下CKEditor的API線上文件說明

 CKEDITOR.config.enterMode
Sets the behavior for the ENTER key. It also dictates other behaviour rules in the editor, like whether the <br> element is to be used as a paragraph separator when indenting text. The allowed values are the following constants, and their relative behavior:

使用方法如下:
找到Provider\HtmlEditorProviders\CKEditor\config.js
加入這段設定即可

config.enterMode = CKEDITOR.ENTER_BR; 

這樣按下Enter鍵後, 原本的p tag就變成br tag了.

2011年3月16日 星期三

SSRS2008 R2 Example DB and Reports

收集SSRS 2008 R2的測試資料和範例報表

AdventureWorks 2008R2 SR1 這是範例資料庫, 不過安裝時,有一個DB因為file group的設定我一直裝不起來...

SQL2008R2.Reporting_Services.Samples , 這是Rerporting Services RDL的範例, 里頭會用到的DB就是上面那個裝不起來的DB....嗟....


幸好還可以下載 AdventureWorks2008R2 without filestream ,  下載下來是一個mdf檔, 直接attach到你的R2 上就可以


他很好心的給你一段attach 的指令

 CREATE DATABASE AdventureWorks2008R2
      ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008\MSSQL\DATA\AdventureWorks2008R2_Data.mdf')  -- change the drive and file path
      FOR ATTACH_REBUILD_LOG ;



快去下載

ps.參考Derek的enable filestream 說明

SQL Server各版本Sample

2011年3月13日 星期日

Stored Procedure中的temp table

前一陣子為了特殊目需要在stored procedure中依不同的原則來宣告table variable
由於無法達成,所以改成create temp table (#xxxTable)的方式然後依不同原則再用alter table drop column 的方式來做
寫在這篇 if .. else .. create table variable

今天在想,用temp table的方式除了是否因為有transaction可能會有performance的考量外, 如果是多人同時間呼叫 sp時, temp table的欄位數和資料內容會不會發瘋??

所以自己做了一個小小的測試, 用二個不同的session來執行以下的sp
 IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[zspBev]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[zspBev]
GO

create procedure zspBev (@type int)
as
begin
    IF  EXISTS (SELECT * FROM tempdb.sys.objects WHERE object_id = OBJECT_ID(N'tempdb..#tmpTable') AND type in (N'U'))
    drop table #tmpTable
    create table #tmpTable
    (col1 int,col2 int)
    begin transaction t1
    if @type = 1
    begin
    insert into #tmpTable values(1,2)
    commit transaction t1
    WAITFOR DELAY '00:00:05';
    select * from  #tmpTable
    end
    else
    begin
        insert into #tmpTable values(3,4)
        commit transaction t1
        WAITFOR DELAY '00:00:10';
        select * from  #tmpTable
    end

    select * from  #tmpTable
end



看來彼此間是不會影響到的. 
在tempdb中查看Temporary Tables目錄下的物件,同時間會有二個#tmpTable開頭的物件,但往後仔細看物件名稱, sql server自己已經有所區別,只是table名稱係漏漏等....
dbo.#tmpTable________________________________________________________________________________________________________000000000036
dbo.#tmpTable________________________________________________________________________________________________________000000000037

所以....就別擔心太多了



2011年3月9日 星期三

停用SSRS Designer Cache

VS2008設計RDL時,如果資料集的欄位有增減,而且增減前已經有做過報表預覽preview,常會讀 到之前cache住的資料,即使重新整理也沒用

通常我會直接刪掉RDL同目錄下副檔名為.rdl.data 的檔案.然後再preview一次就OK

如果每次都嫌麻煩, 那就直接改RS的設定檔

C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\RSReportDesigner.config 把
<Add Key="CacheDataForPreview" Value="true" />
改成
<Add Key="CacheDataForPreview" Value="fasle" />

缺點是,如果 資料查詢很慢,那你就每次preview時都要等執行完畢才能看到結果囉

所以當你要連到正式資料庫設計時,利用cache data會比較好一些

2011年3月7日 星期一

if .. else .. create table variable

想要動依不同情況建立相同名稱的table variable,語法如下
 if @condition = '1'
begin
  declare @tmptable1 table (col1 int,col2 int)
end
else
begin
  declare @tmptable1 table (col1 int,col2 int, col3 int, col4 int)
end

出現以下錯誤
Msg 134, Level 15, State 1, Line 13
The variable name '@tmptable1' has already been declared. Variable names must be unique within a query batch or stored procedure.

改成用temp table 也不行
 if @condition = '1'
begin
    create table #tmptable1  (col1 int,col2 int)
end
else
begin
   create table #tmptable1  (col1 int,col2 int, col3 int, col4 int)
end


 出現以下錯誤
Msg 2714, Level 16, State 1, Line 15
There is already an object named '#tmptable1' in the database.

最後折衷好了...馬是口以啦...

 create table #tmptable1  (col1 int,col2 int, col3 int, col4 int)
 if @condition = '1'
begin
    alter table #tmptable1
    drop column col3,col4
end

 

2011年3月3日 星期四

SSRS 限定一頁顯示N筆資料

同事設計RDL想要一頁只顯示10筆清單資料就強迫換頁.

於在報表上,依這段Expression 建立一個群組Group,每頁顯示10筆後跳新分頁

=Fix((RowNumber("DataSet1")-1) /10)

預覽時,發生這個錯誤

 [rsInvalidGroupExpressionScope] A group expression for the grouping ‘Group1’ uses the RowNumber function with a scope parameter that is not valid.  When used in a group expression, the value of the scope parameter of RowNumber must equal the name of the group directly containing the current group.   

大家在RowNumer的scope上測來測去都是同樣的錯,真不知該給什麼好....



最後是給上了nothing 就解決了  =Fix((RowNumber(nothing   )-1) /10)

查了MSDN上的說明, 有看沒有懂,

因為很直覺的是RowNumber的scope應該是dataset啊..不是嗎???

Scope

每個彙總函數都使用 Scope 參數,它用來定義彙總函數的執行範圍。有效範圍是群組、資料集或資料區域的名稱。只有直接或間接包含運算式的群組或資料區域可用來作為範圍。對於資料區域 內的運算式而言,所有彙總函數的 Scope 都是選擇性的。如果您省略 Scope 參數,彙總範圍便是報表項目所屬的最內層資料區域或群組。指定 Nothing 範圍會將範圍設為報表項目所屬的最外層資料區域。
對於資料區域之外的運算式,Scope 是指資料表或商務物件。如果報表包含多個資料集,Scope 就是必要的。如果報表只包含單一資料集,便會省略 Scope,範圍會設為資料集。您不能針對在資料區域之外的報表項目來指定 Nothing 關鍵字。
頁首或頁尾不能使用 Scope 參數。

publish error allowDefinition='MachineToApplication'

一個老舊的aspx web form專案,調了一些功能建置成功,但進行部署時顯示以下錯誤。 在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為...