2011年12月22日 星期四

批次刪除檔案

想要在某一目錄包含其子目錄下,快速刪除.xls的檔案
其中,想要排除某一子目錄 不要處理

REM 先將保留的目錄下所有檔案屬性設為唯讀
attrib /s .\reserved\*.xls +r +a > NUL 
REM /s刪除檔案(含子目錄)
del /s .\*.xls 
REM  再將保留的目錄下所有檔案屬性還原
attrib /s .\reserved\*.xls -r -h -s > NUL

2011年11月22日 星期二

PL/SQL Developer 無法登入

PL/SQL Developer類似SSMS 的功能, 連結到oracel db GUI工具

今天安裝了Oracle 10.2 client後 net manager 設定及測試連結都OK

但安裝了PL/SQL Developer 7.0.2.1076 後,卻無法連線,出現以下錯誤

Initialization error 
Could not locate OCI dll

OracleHomeKey: SOFTWARE\ORACLE\KEY_OraClient10g_home1
OracleHomeDir: E:\oracle\product\10.2.0\client_1

參考此篇文章 Could not locate OCI dll Error 

將 E:\oracle\product\10.2.0\client_1\ 下的所有單一檔案 (不包含目錄)複製並覆蓋到 E:\oracle\product\10.2.0\client_1\bin\ 下即可

2011年11月8日 星期二

SQL 2008 R2 Drillthrough slow

環境:
windows 7 enterprise  with sp1 + SQL Server 2008 R2 standard 10.50.2500
or
windows 2008 R2 enterpeise with sp1 + SQL Server 2008 R2 enterprise 10.50.2500
 
SSAS Dimension 25個, 若單人多次或多人一次進行dirllthrough時,此時記憶體使用量急上升,直到用滿了為止,接著就出現以下的錯誤,

同事反覆測試後的結論是, 在10.50.1600時不會有問題,記憶體使用量也不會暴增


TITLE: Microsoft SQL Server Management Studio
------------------------------

The selected action cannot be completed because of the following error.
伺服器: 已因記憶體不足的壓力而取消作業。
伺服器: 已因記憶體不足的壓力而取消作業。
This error may have occurred because the definition for the action is not valid. Verify the definition using the Actions view.

------------------------------
ADDITIONAL INFORMATION:

伺服器: 已因記憶體不足的壓力而取消作業。
伺服器: 已因記憶體不足的壓力而取消作業。 (Microsoft SQL Server 2008 R2 Analysis Services)


反應給MS,最後獲得的回答是在CU6之後會有此問題, 要等SQL Server 2012才會修正. 
目前可提供了一個解決方法
1、 開啟下列的檔案:
C:\Program Files\Microsoft SQL Server\MSAS10_50.Instance Name\OLAP\Config\ msmdsrv.ini
2、 修改下列的值
原本的值:
<SpaceDecomposition>8</SpaceDecomposition>
修改後的值:
<SpaceDecomposition>11</SpaceDecomposition>
3、 重新啟動 SQL Server Analysis Services

測試後,解決了問題. 恭喜大家,歷經一個月的溝通與測試終於解決了...

 

 2022/08/26 後記...

在SSAS 2019上,遇到drillthrough 很慢很慢的問題,同樣地調整這個參數後,健步如飛啊。

2011年10月29日 星期六

四捨五入不進位??


人客反應一個四捨五入到小數二位的問題...
我沒什麼頭緒要怎麼解決, 但在不小心中發現一個方法,暫時可以解決四捨五入不進位的問題
這是sql server 的float bug嗎, 還是本來就這樣??

二組數字分別是1.055, 1.1243,型態是float
依四捨五入到小數第二位的話,  結果應該是  c1 =  1.06  c2= 1.12
但結果卻不如人意,而且只有當此float 刪好只有到小數第三位時,欲四捨五入進位到小數二位才會有問題


先reproduce一下狀況..
declare @tab table (c1 float,c2 float)
insert into @tab
select 1.055, 1.1243

select 
c1,c2
,cast(c1 as decimal(5,2)) as r1,cast(c2 as decimal(5,2)) as r2
,cast(c1 + 0.001 as decimal(5,2)) as t1,cast(c2 + 0.001 as decimal(5,2)) as t2
,cast(c1 + 0.0001 as decimal(5,2)) as s1,cast(c2 + 0.0001 as decimal(5,2)) as s2
 from @tab

但結果如下

c1 c2 r1 r2 t1 t2 s1 s2
1.055 1.124 1.05 1.12 1.06 1.13 1.06 1.12

有趣的是, 1.124 + 0.001 =  1.125 , 轉成decimal(5,2)後,又很精準的四捨五入了, 但結果是不對的....


所以再做下列測試
如果c1為1.0551 又或者將型態改成decimal(5,4)  則結果是正確的

declare @tab table (c1 float,c2 float)
insert into @tab
select 1.0551, 1.124

select  
c1,c2
,cast(c1 as decimal(5,2)) as r1,cast(c2 as decimal(5,2)) as r2
,cast(c1 + 0.001 as decimal(5,2)) as t1,cast(c2 + 0.001 as decimal(5,2)) as t2
,cast(c1 + 0.0001 as decimal(5,2)) as s1,cast(c2 + 0.0001 as decimal(5,2)) as s2
 from @tab

c1 c2 r1 r2 t1 t2 s1 s2
1.0551 1.124 1.06 1.12 1.06 1.13 1.06 1.12



declare @tab table (c1 decimal(5,4),c2 decimal(5,4))
insert into @tab
select 1.055, 1.124

select  
c1,c2
,cast(c1 as decimal(5,2)) as r1,cast(c2 as decimal(5,2)) as r2
,cast(c1 + 0.001 as decimal(5,2)) as t1,cast(c2 + 0.001 as decimal(5,2)) as t2
,cast(c1 + 0.0001 as decimal(5,2)) as s1,cast(c2 + 0.0001 as decimal(5,2)) as s2
 from @tab

c1 c2 r1 r2 t1 t2 s1 s2
1.055 1.124 1.06 1.12 1.06 1.13 1.06 1.12

將小數點變成四位後,四捨五入到小數二位就對了

再來一個測試
declare @tab table  (c1 float,c2 float)
 insert into @tab
select 1.055, 1.124

select  
c1,c2
,cast(c1+0.000 as decimal(5,2)) as r1,cast(c2 as decimal(5,2)) as r2
,cast(c1 + 0.001 as decimal(5,2)) as t1,cast(c2 + 0.001 as decimal(5,2)) as t2
,cast(c1 + 0.0001 as decimal(5,2)) as s1,cast(c2 + 0.0001 as decimal(5,2)) as s2
 from @tab


c1 c2 r1 r2 t1 t2 s1 s2
1.055 1.124 1.05 1.12 1.06 1.13 1.06 1.12

加上0.000是沒有用的...

結論:
1.float使用真的要小心謹慎,不是那麼精準
2.四捨五入到小數二位, 則先加0.0001變成有小數四位後,再進行四捨五入

大家有看懂嗎???


2011年10月20日 星期四

Informix執行計劃

執行SQL前,先執行下列
SET EXPLAIN ON  , 開啟執行計劃, 要整個跑完後才能看
SET EXPLAIN OFF, 關閉執行計劃
SET EXPLAIN ON AVOID_EXECUTE, 開始執行計劃,但只評估不執行

所以查看SQL 用到index的狀況,可選擇第3種方式
詳細使用可查看informix online help

完成後會輸出到 sqexplain.out
vi 查看內容如下

QUERY:
------
select * from test

Estimated Cost: 453
Estimated # of Rows Returned: 8835

  1) xxxx.test: SEQUENTIAL SCAN

QUERY:
------
select * from ss_code

Estimated Cost: 453
Estimated # of Rows Returned: 8835

  1) xxxx.test: SEQUENTIAL SCAN
~
~
"sqexplain.out" 21 lines, 263 characters

2011年10月19日 星期三

Could not load file or assembly 'ReportingServicesNativeClient

在Windows 2008 R2上安裝 SQL Server 2005 64位元
Reporting Server 網站進入時出現下列錯誤
Could not load file or assembly 'ReportingServicesNativeClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. An attempt was made to load a program with an incorrect format.
找到討論回文,照做後,問題解決轉貼abhijitc的回文
 The problem is not SSRS, the problem is asp runing on 32-64 bits. to enable the SSRS follow these steps:
1. To run the 64-bit version of ASP.NET 2.0, Click Start, click Run, type cmd, and then click OK.

2. Type the following command to disable the 32-bit mode:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 0
3. Type the following command to install the version of ASP.NET 2.0 and to install the script maps at the IIS root and under:
%SYSTEMROOT%\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe -i
4. Make sure that the status of ASP.NET version 2.0.50727 is set to Allowed in the Web service extension list in Internet Information Services Manager.

5. Check the SSRS configuration

Note The build version of ASP.NET 2.0 may differ depending on what the currently released build version is. These steps are for build version 2.0.50727.

view this link : http://support.microsoft.com/kb/894435/en-us

2011年9月14日 星期三

無法安裝silverlgiht tool 4

vs 2010安裝 silverlight tool 4 無法安裝, 出現

Visual Studio 2010 or Visual Web Developer Express 2010 or Visual Phone Developer Express 2010 that matches the language version of Silverlight Tools 4 must be installed before installation of Silverlight Tools can continue. Silverlight Tools is available in other languages at http://go.microsoft.com/fwlink/?LinkId=177432

試了很多方法..還是無法安裝, 最後參考這篇文章, 先移除vs 2010 SP1後, 就可以安裝tool了.

裝完後再重裝vs2010 SP1

2011年7月20日 星期三

powerdesigner 15 產生SQL指令

設計好PDM,接下來就要在DB上把物件都建立起來.

到  Database >> Generate Database  產生create 語法檔

結果出錯了,原來產生出來的create table  syntax中, 欄位的data type都變成了domain name 了

到 Database >> Edit Current DMBS >> Script >> Objects >> Domain >> Enable , 將Value點選為No即可

  
但問題又來了, 明明是int和smallint的欄位, 怎麼create table 中變成後加collate ??

/*==============================================================*/
/* Table: BatchLog                                              */
/*==============================================================*/
create table dbo.BatchLog (
   BatchLogID             int                  identity(1, 1),
   StartDateTime        datetime             not null,
   EndDateTime          datetime             null,
   Status                      smallint             collate Chinese_Taiwan_Stroke_CI_AS  not null,
   ProjectCode          nvarchar(256)        collate Chinese_Taiwan_Stroke_CI_AS null,
   StartDate               int                  collate Chinese_Taiwan_Stroke_CI_AS null,
   EndDate                int                  collate Chinese_Taiwan_Stroke_CI_AS null,
   constraint PK_BatchLog primary key (BatchLogID)
         on "PRIMARY"
)
on "PRIMARY"
go

有夠奇怪啦...找了半天, 才發現原來剛開始這些table是由現存DB反向轉成PDM的
轉入時,字串欄位在Microsoft 頁籤,都會將Collation name一起轉入

後來當把某些字串欄位分別改成了smallint及int型態時, PD15並未將其Collation name 給清空, 所以在generate script時,就變成了上面那樣了.

最後一個個欄位調整, 重建一下script就OK了.



所以如果有指定collation時,當改變資料型態時要記得自已去刪掉collation 定義.

2011年7月19日 星期二

VS2011 Pluralization of name

表格名稱若帶有s字母結尾, 使用Linq to SQL,建立.dbml時

記得先做下列設定..

Tools >> Options  >> Database Tools >> O/R Designer >> Pluralization  of name

Enabled 設成 False

不然VS2010會亂亂命名class , 有s的亂改成沒s, 沒有s的自已亂改成有s,


Pluralization  of name = 名稱的複數表示

我咧傻傻搞不清

2011年7月17日 星期日

IIS 7無法上傳超過30MB 檔案

網站由windows 2003換到windows 2008後, 上傳大旳檔案時會出現404 not found的錯

web.config httpruntim 有設定maxlength, 但仍無法上傳, google 到此篇
以下是更改設定指令.

REM切換到appcmd目錄
cd c:\Windows\systems32\inetsrv

REM 先備份IIS設定
appcmd add backup test20110718

REM 查看IIS備份紀錄是否存在
appcmd list backup

REM 先查主機的SiteName及APP list
appcmd list app

REM 查看目前上傳設定,找關鍵字requestLimits
appcmd list config "Default Web Site/mySite" -section:requestFiltering

REM 更改size 單位為byte ,以下為100MB左右
appcmd set config "Default Web Site/mySite" -section:requestFiltering -requestLimits.maxAllowedContentLength:102400000 -commitpath:apphost



2011年7月14日 星期四

powerdesigner 15 取消欄位 Code = Name

新增表格定義時,輸入欄位Name有時不想要同步到Code,

可在Tools >> General Options , 點選左方選單Dialog, 反勾選Name to Code mirroring



如果table要顯示的是code而不是name
Tools >> Model Options >> Naming Conventions >> Display 改成Name即可


每次必忘的設定, 每次都要找一下....

2011年7月13日 星期三

powerdesigner 15 文件範本

powerdesigner功能愈來愈多,表示使用上也愈來愈複雜

產生文件時,通常會先編輯好文件範本.
不然使用內定的範本後,產生出來的文件內容挺不實用的

PD15中,文件的功能也多了許多,常用的

1.希望物件依code排序,
在item 按mouse 右鍵,選 selection 進入後, 第一行S 就是排序選項, 勾選你要排序的欄位為Code即可

  
2.table 產出格式

 在item 按mouse 右鍵,選Layoyt進入後, 可勾選要顯示的Attribute, 同時也可設定欄位寬度
通常會選的就是下面這幾項




2011年7月12日 星期二

windows 2003 IIS 顯示silverlight

把原本部署在IIS7的網站改部署到windows 2003 R2 IIS上,

如果在顯示silverlight物件時,出現了這個錯誤....

網頁錯誤詳細資料

使用者代理程式: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Foxy/1; .NET CLR 1.1.4322; InfoPath.3; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
時間戳記: Tue, 12 Jul 2011 09:43:13 UTC


訊息: Unhandled Error in Silverlight Application
Code: 2104   
Category: InitializeError      
Message: 2104 發生錯誤。    
行: 47
字元: 13
程式碼: 0
URI: http://bev2003/Demo/Scripts/jquery.silverlight.js






google找到以下訊息, 是IIS少了silverlight檔案的關聯設定


  • .xap application/x-silverlight-app

  • .xaml application/xaml+xml

  • .xbap application/x-ms-xbap 


  • 主要是在IIS 本機電腦,按右鍵選內容, 在MIME類型加入幾上三個檔案即可.

    2011年7月11日 星期一

    powerdesigner 轉出五個meta data table

    如果手上只有PDM,..想要產生 meta data table

    Tools >> powerbuilder >>Generate Extended Attributes...


    當然要先匯入powerbuilder extension,
    Tool >>Extension >>Import an Extension,勾選powerbuilder

    同時先準備好五個meta data table schema, 欄位名稱不能更改,但字串欄型態可加長.


    CREATE TABLE [dbo].[pbcatcol](
        [pbc_tnam] [char](30) NOT NULL,
        [pbc_tid] [int] NULL,
        [pbc_ownr] [char](30) NULL,
        [pbc_cnam] [char](30) NOT NULL,
        [pbc_cid] [smallint] NULL,
        [pbc_labl] [nvarchar](254) NULL,
        [pbc_lpos] [smallint] NULL,
        [pbc_hdr] [nvarchar](254) NULL,
        [pbc_hpos] [smallint] NULL,
        [pbc_jtfy] [smallint] NULL,
        [pbc_mask] [nvarchar](31) NULL,
        [pbc_case] [smallint] NULL,
        [pbc_hght] [smallint] NULL,
        [pbc_wdth] [smallint] NULL,
        [pbc_ptrn] [nvarchar](31) NULL,
        [pbc_bmap] [char](1) NULL,
        [pbc_init] [nvarchar](254) NULL,
        [pbc_cmnt] [nvarchar](4000) NULL,
        [pbc_edit] [nvarchar](31) NULL,
        [pbc_tag] [nvarchar](254) NULL,
     CONSTRAINT [PK_pbcatcol] PRIMARY KEY CLUSTERED
    (
        [pbc_tnam] ASC,
        [pbc_cnam] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
     
     GO
     
    CREATE TABLE [dbo].[pbcatedt](
        [pbe_name] [nvarchar](30) NOT NULL,
        [pbe_edit] [nvarchar](254) NULL,
        [pbe_type] [smallint] NOT NULL,
        [pbe_cntr] [int] NULL,
        [pbe_seqn] [smallint] NOT NULL,
        [pbe_flag] [int] NULL,
        [pbe_work] [char](32) NULL,
     CONSTRAINT [PK_pbcatedt] PRIMARY KEY CLUSTERED
    (
        [pbe_name] ASC,
        [pbe_seqn] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
     
    CREATE TABLE [dbo].[pbcattbl](
        [pbt_tnam] [char](30) NOT NULL,
        [pbt_tid] [int] NULL,
        [pbt_ownr] [char](30) NULL,
        [pbd_fhgt] [smallint] NULL,
        [pbd_fwgt] [smallint] NULL,
        [pbd_fitl] [char](1) NULL,
        [pbd_funl] [char](1) NULL,
        [pbd_fchr] [smallint] NULL,
        [pbd_fptc] [smallint] NULL,
        [pbd_ffce] [char](32) NULL,
        [pbh_fhgt] [smallint] NULL,
        [pbh_fwgt] [smallint] NULL,
        [pbh_fitl] [char](1) NULL,
        [pbh_funl] [char](1) NULL,
        [pbh_fchr] [smallint] NULL,
        [pbh_fptc] [smallint] NULL,
        [pbh_ffce] [char](32) NULL,
        [pbl_fhgt] [smallint] NULL,
        [pbl_fwgt] [smallint] NULL,
        [pbl_fitl] [char](1) NULL,
        [pbl_funl] [char](1) NULL,
        [pbl_fchr] [smallint] NULL,
        [pbl_fptc] [smallint] NULL,
        [pbl_ffce] [char](32) NULL,
        [pbt_cmnt] [nvarchar](4000) NULL,
     CONSTRAINT [PK_pbcattbl] PRIMARY KEY CLUSTERED
    (
        [pbt_tnam] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]

    GO


     
    CREATE TABLE [dbo].[pbcatvld](
        [pbv_name] [nvarchar](30) NOT NULL,
        [pbv_vald] [nvarchar](254) NOT NULL,
        [pbv_type] [smallint] NOT NULL,
        [pbv_cntr] [int] NULL,
        [pbv_msg] [nvarchar](254) NULL,
     CONSTRAINT [PK_pbcatvld] PRIMARY KEY CLUSTERED
    (
        [pbv_name] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]

    GO

    轉出過程中, 其實PD會產生insert 及update 語法, 所以上述五個table應設立PK或Unique Index,以避免重覆轉入

    若手動修改了五個table的內容想要反向更新PDM時,則

    Tools >> powerbuilder >>Reverse Engineering Extended Attributes...就轉回來了.

    powerdesigner 反向轉出PDM

    剛開始寫程式是由powerbuilder 6.0開始的.
    所以理所當然,剛開始使用case tool也就是使用powerdesigner 6.0


    二者結合後有個很不錯的功能就是可以將做好的PDM直接轉出powerbuilder設計時使用的五個meta data table ,分別是
    pbcatcol ,放置表格欄位, 類似sql server 2005 的sys.columns
    pbcatedt,放置powerbuilder design時用的edit style, 如果開發過pb的應用系統,你會很高興有這個
    pbcatfmt,放置powerbuilder design時用的foramt,也是用在開發pb
    pbcattb,放置資料表, 類似sql server 2005 的sys.tables
    pbcatvld,放置驗證原則.

    以上幾個table,除了pbcatvld沒使用過外,其他4個在開發powerbuilder的程式時,一定是SA/SD必備且必要的設計工具了. 不然programmer在coding設計UI時真的會叫苦連天

    時過多年,我已經久違powerbuilder多年, 但每次在交付資料庫設計文件時, 一定都不忘附上PDM以及相關的report, 所以無論如何, 不管是先設計PDM還是先設計資料庫開表格, 到最後一定都會產出這幾個table

    powerdesigner在敝公司真是個老牌的case tool, 許多同事時至今日仍然在使用pd 6.0, 即便這個產品已經進化到15.0的版本了.但大家仍舊喜愛使用pd 6.0來進行SA/SD. 因為他算是所有pd的版本中最容易使用,最容易理解的一版了.


    對我而言, 因為很習慣直接在sql server 中先design,所以通常我都會先在sqlserver先編輯好欄位中文後, 然後再於pd中反向產出PDM .因為主要都是想利用pd產出資料庫的文件.

    然而,其他同事則是習慣在pd中新建PDM,然後再產生實體資料庫.

    powerdesigner從6.0開始就提供了正向與反向產生PDM或db table schema的功能

    在pd 15中,如果要由DB產出PDM,則在File >>Reverse Engineer>>Database
    連接到要轉出的DB類型後,
     先在Extension頁籤, 勾選PowerBuilder (為了日後可幾進行正反向轉換)
    如果要事後匯入,可以在開啟PDM後, 在Tool >>Extension >>Import an Extension,勾選powerbuilder
     選擇要轉入的資料庫連線
     這樣就完成PDM.

    最後,如果你是像我一樣,習慣在sql server description 維護資料表及欄位 中文說明,則產生完PDM後, 可利用 Tools >>Execute Command >>Edit/Run Script執行下列指令碼, 將comment轉換成name, 這樣你的PDM就同時可呈現欄位名稱及中文說明了.



    Option Explicit

    ValidationMode = True
    InteractiveMode = im_Batch 

    Dim mdl   
    Set mdl = ActiveModel

    If (mdl Is Nothing) Then
     MsgBox "There   is   no   current   Model "
    ElseIf ( Not mdl.IsKindOf(PdPDM.cls_Model) ) Then
     MsgBox "The   current   model   is   not   an   Physical   Data   model. "
    Else
     ProcessFolder mdl
    End If

    Private Sub ProcessFolder(folder)

     On Error Resume Next

     Dim tbl 'table
     For Each tbl In folder.tables
     
      If (Not tbl.IsShortcut) Then
       tbl.name = tbl.comment 
       Dim col 'column
       For Each col In tbl.columns
        If col.comment = "" Then
        Else
         col.name = col.comment
        End If
       Next
      End If
     Next

     Dim view 'view
     For Each view In folder.views
      If (Not view.IsShortcut) Then
       view.name = view.comment
      End If
     Next

     Dim f
     For Each f In folder.Packages
      If (Not f.IsShortcut) Then
       ProcessFolder f
      End If
     Next

    End Sub


    無論用什麼工具, 前提就是利用PD提供的正反向功能將苦差事做一次就好吧.

    2011年6月12日 星期日

    SSRS畫甘特圖

    看到這篇文章 ,

    Gantt charting for the holidays


    SSRS也能做出甘特圖,看了一下 screenshot,

    把隨附的rdl檔下載下來

    改了一下dataset 的內容,查看了里頭的圖表設置. 很有創意
    SELECT     Project, Task, TaskSequence,
               StartDate, EndDate, PercentComplete,
               DATEDIFF(DAY, StartDate, EndDate)
                      * PercentComplete AS CompletedDays,
               DATEDIFF(DAY, StartDate, EndDate)
                      * (1 - PercentComplete) AS RemainingDays
    from
    (
    select
     'Holiday Planner 2007' as Project
    ,'Make List' as Task
    ,1 as TaskSequence
    ,'2007-07-01' as StartDate
    ,'2007-10-01' as EndDate
    ,1 as PercentComplete 
    union all
    select 'Holiday Planner 2007', 'Check List Twice',2,'2007-08-01','2007-11-01',1
    union all
    select 'Holiday Planner 2007', 'Make Gifts',3,'2007-09-01','2007-12-01',.9
    union all
    select 'Holiday Planner 2007', 'Pack Gifts',4,'2007-12-10','2007-12-24',.65
    union all
    select 'Holiday Planner 2007', 'Deliver Gifts',5,'2007-12-24','2007-12-26',0
    ) as Project

    實做上,主要是用bar stacked chart 設計了五個series data做出來的效果

    Series1: 放StartDate, 但為了讓X軸在圖表呈現不那麼擁擠,所以將此日期依@LabelBuffer參數值(預設是10)往前推10天,可以更改一下這個數值,來觀看Label的變化,數值愈小,則Label在圖表上就愈顯擁擠,  這個series的color設成和backgroud一樣的白色


    Series2:放@LabelBuffer,這是要放置開始日期StartDate的label顯示, 同時把Angle設成-35,這樣在呈現時比較有交錯不會有擠在一起的感覺,這個series的color設成和backgroud一樣的白色

    Series3: 放 CompletedDays, 範例是PercentComplete 欄位來計算出完成天數

    Series4:放RemainingDays, 範例是以1- PercentComplete來計算出剩餘天數
     
    Serires3及4需給定不同的color , 因為這是主要要顯示二段bar


    如果StartDate ~ EndDate是100天, PercentComplete 是0.7,則CompletedDays是70天, RemainingDays則為30, 當然,前提是資料來源必需要先計算出已完成的百分比,
    所以這幾項欄位可以自已的實際情況來改寫


    Series5:放 @LabelBuffer, 作用和Series2一樣, 這是要放置結束日期EndDate的label顯示,所以color也要設成白色

    最後用現行的bug tracker依樣畫一張..挺不錯的


    2011年5月31日 星期二

    中繼資料管理員有錯誤

    某天,啟動SSAS後,想要檢視Server Properties, 結果出現了這個莫名的錯誤



     中繼資料管理員有錯誤。 'Market Basket ~MC' Cube 所參考的識別碼為 'Market Basket ~MC-Order Number',名稱為 'Market Basket ~MC-Order Number' 的維度不存在。
    中繼資料管理員有錯誤。 從檔案 '\\?\C:\Program Files\Microsoft SQL Server\MSAS10_50.SQL2008\OLAP\Data\Adventure Works DW 2008R2 SE.0.db\Market Basket ~MC.1.cub.xml' 載入 Market Basket ~MC cube 時發生錯誤。
     (Microsoft.AnalysisServices)




     
    切到目錄下查看, 刪除掉Market Basket ~MC.1.cub.xml後再檢視一次Server Properties, 這次出現Market Basket.3.dms.xml發生錯誤.


    最後將所有Market Basket開頭的檔案都刪掉就正常了. 這些看來都是sample cube,所以不要也罷

    2011年5月30日 星期一

    SQL Server 找不到或無法存取伺服器

    裝了一台SQL Server 2005,本機連結都沒問題, 但外部電腦要連進來時出現

    例外物件:System.Data.SqlClient.SqlException
    例外訊息:建立連接至 SQL Server 時,發生網路相關或執行個體特定的錯誤。找不到或無法存取伺服器。確認執行個名稱是否正確,以及 SQL Server 是否設定為允許遠端連線。 (provider: SQL 網路介面, error: 26 - 搜尋指定的伺服器/執行個體時發生錯誤)
    例外來源:Void OnError(System.Data.SqlClient.SqlException, Boolean)

    檢查了 SQL Server Surface Area Configuration 下的Surface Area Configuration
    DAC (Enable remote  DAC)也有勾選
    防火牆也關了
    但外部連結仍然不通.

    最後查到是因為我把 SQL Server Browser 服務給關掉了,  開啟後連線就OK了.


    MSDN上說明SQL Server Browser服務 ,  我也是一如往常...有看沒有很懂(....汗)


    SQL Server Browser 服務
    SQL Server Browser 程式以 Windows 服務執行。SQL Server Browser 會接聽 MicrosoftSQL Server 資源的內送要求,並提供有關電腦上所安裝之 SQL Server 執行個體的資訊。SQL Server Browser 完成下列動作:
    • 瀏覽可用伺服器的清單
    • 連接到正確的伺服器執行個體
    • 連接到專用管理員連接 (DAC) 端點

    2015/08/08
    如果db主機開啟了windwos firewall,那要記得查看UDP 1443是否有在輸入原則 啟用。

    2011年5月24日 星期二

    伺服器 'XXX' 上的 MSDTC 無法使用

    使用某套裝軟體的某項任務新增功能
    結果出現了 伺服器 'XXX' 上的 MSDTC 無法使用的錯誤訊息

    原來是服務下的 Distributed Transaction Coordinator未啟動

    但開啟服務後,程式跑了半天出不來...

    查看事件檢視器發現有一個警告

    MS DTC 無法與遠端系統的 MS DTC 通訊。 主要系統的 MS DTC 與次要系統的 MS DTC 建立了 RPC 繫結。 但是次要系統並沒有在逾時期間到期之前 建立反轉 RPC 繫結至主要 MS DTC 系統。 請確認兩個系統之間有網路連線。....

    查了半天,原來才發現, 一台Web Server,一台DB Server, 但其中一台的WINDOWS防火牆有開啟,另一台是關閉的.
    把防火牆關起來後,就一切正常了.

    2011年5月18日 星期三

    JQuery UI.Layout使用

    前二週用了JQuery UI做了一個project 的demo,效果不錯.
    另外,也想要讓網頁中的物件可自動隨著螢幕大小resize,之前同事自已寫了一個javascript function,雖然效果不錯,但有時在某些頁面時仍得要再呼叫一次resize

    但有時版面總不如意啊.  所以想使用JQuery UI.Layout這個plug-in看看

    試了幾天,雖然有 文件參考  ,但也搞得我七葷八素的, 有些方法或屬性是有看沒有懂..(汗....)
    測了好幾天 後,總算抓到了一些撇步了

    先建一個Website Application, 原則上Visual Studio 2010會幫你建一個看起來UI效果還不錯的網站.

    先在Site.Master.aspx中加入jquery-1.6.min.js、jquery.layout-latest.js、layout-default-latest.css等檔案的參考, 然後加入這段 script

    <script type="text/javascript">
            var myLayout;
            $(document).ready(function () {
                //先設定大小再凍結resizer bar
                myLayout = $('body').layout({ applyDefaultStyles: true
                                                 , north__closable: false
                                                 , north__pane_spacing: 0
                                                 , north__resizable: false 

                });
               //這個是想要讓header預設不要出現scrollbar,如果不設,下拉功能選單會出不來
              //和直接設定north__showOverflowOnHover:    true的效果又不一樣
              //且讓asp:menu選單下拉時的z-index在最上面
              //如果把這行拿掉,menu就被蓋在下面都出不來了....
                myLayout.allowOverflow('north');
            });
    </script>

    上面紅字那段try了二天二夜....真是血淚(哭....)

    如果要override pane的css屬性,

    可以直接在Site.css加入以下..
     .ui-layout-pane-north {
         border: 0 !important;
         padding:0 !important;
         margin-bottom:0 !important;
         background: none !important;
    }
    .ui-layout-pane-center {
         border: 0 !important;
         padding:0 !important;
         margin-bottom:0 !important;
         background: none !important;
    }

    然後在body中放二個div tag

    先放
     <div class="ui-layout-center"> 
            <asp:ContentPlaceHolder ID="MainContent" runat="server" /> 
    </div>

    再放
    <div class="ui-layout-north">
            <div class="header">
                <div class="title">
                  .........
                </div>
                <div class="loginDisplay">
                 ............
                 </div>
            </div>
            <div class="clear hideSkiplink">
                    <asp:Menu ID="Menu1" runat="server" CssClass="menu" EnableViewState="False" DataSourceID="SiteMapDataSource1"
                        Orientation="Horizontal" StaticSubMenuIndent="16px" OnMenuItemDataBound="Menu1_MenuItemDataBound">
                        <StaticMenuItemStyle HorizontalPadding="20px" VerticalPadding="5px" />
                        <DynamicMenuStyle CssClass="adjustedZIndex" />
                    </asp:Menu>
                </div>
    < /div>

    更多的說明及用法可以好好參考 demo site

    做好框架後, 加入幾個頁面,測試了放了updatepanel ,gridview, reportviewer(rdlc), jquery ui accordin及dialog的效果

    看來都很完美....

    要注意的是reportviewer設置要如下

     <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="100%" Height="100%"  SizeToReportContent="true" >
        </rsweb:ReportViewer>

    width和height有沒有設100%好像沒關係, 但SizeToReportContent是一定要設的,這樣就會依螢幕大小自已resize 了

    最後.....轉圈...灑花.....



    2011年5月10日 星期二

    使用LINQ 將 選取的listbox item轉成string 或string array

    using System.Web.UI.WebControls;

    string strArray[] = listboxTest.Items.Cast<ListItem>().Where(item => item.Selected).Select(p => p.Value).ToArray();

     string strTest = String.Join(",", listboxTest.Items.Cast<ListItem>().Where(item => item.Selected).Select(p => p.Value).ToArray());
             

    Informix Debug方式

    在stored procedure 中, 任一要trace的地方
    set debug file to "xxxxx.out";

    如果要trace所有的變數
    trace on;



    如果要trace些變數,則利用參數concation方式,
    trace variableName1||variableName2 ;

    最後記得要 將trace 關掉..
    trace off;


    create procedure spTest()
       define variableName1 varchar(10); 
      define variableName2 varchar(10);

      set debug file to 'abc.out';

      foreach
         select col1, col2 
             into  variableName1,variableName2
           from  testTable

          trace variableName1||variableName2 ;
      end foreach;

      trace off;
    end procedure ;

    2011年4月23日 星期六

    windows 2003 開關小事

    安裝windows 2003時,總要參考的二篇Microsoft KB

    關閉 關機事件追蹤器
    1. 按一下 [開始],再按一下 [執行]
    2. 輸入 gpedit.msc,再按一下 [確定]
    3. 展開 [電腦設定],展開 [系統管理範本],再展開 [系統]
    4. 按兩下 [顯示關機事件追蹤器]
    5. 按一下 [已停用],再按一下 [確定]

    開啟 Windows 中的自動登入

    1. 按一下 [開始],然後按一下 [執行]
    2. [開啟] 方塊中,輸入 Regedt32.exe,然後按下 ENTER。
    3. 在登錄中找出下列子機碼:
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
    4. 按兩下 [DefaultUserName] 項目,輸入您的使用者名稱,然後按一下 [確定]
    5. 按兩下 [DefaultPassword] 項目,輸入您的密碼,然後按一下 [確定]注意:如果 DefaultPassword 值不存在,您必須新增該值。如果要新增這個值,請依照下列步驟執行:
      1. [編輯] 功能表上,按一下 [新增],然後指向 [字串值]
      2. 輸入 DefaultPassword,然後按 ENTER。
      3. 按兩下 [DefaultPassword]
      4. [編輯字串] 對話方塊中,輸入您的密碼,然後按一下 [確定]
      注意:如果沒有指定 DefaultPassword 字串,Windows 就會自動將 AutoAdminLogon 機碼的值從 1 (True) 變更為 0 (False),以停用 AutoAdminLogon 功能。

    6. [編輯] 功能表上,按一下 [新增],然後指向 [字串值]
    7. 輸入 AutoAdminLogon,然後按 ENTER。
    8. 按兩下 [AutoAdminLogon]
    9. [編輯字串] 對話方塊中,輸入 1,然後按一下 [確定]
    10. 結束 [登錄編輯程式]。
    11. 按一下 [開始],按一下 [關機],然後在 [註解] 文字方塊中輸入原因。
    12. 按一下 [確定] 以關閉您的電腦。
    13. 重新啟動您的電腦。現在,您已經可以自動登入。

    2011年4月16日 星期六

    The LocaleIdentifier property is not overwritable and cannot be assigned a new value

    在SSAS 2008R2上,還原了一個用SSAS2005做出來的cube (*.abf)
    瀏覽Broese Cube時, 出現了這個錯誤畫面

    The LocaleIdentifier property is not overwritable and cannot be assigned a new value



    參考這篇討論

    若在SSMS上,則請於上圖所示, 將Language由Default改成Chinese(Taiwan),重新連結一下(Reconnect)一下就正常了

    若是透過程式連結,則在connectionstring 加入Locale Identifier=1033, 像這樣

    <add name="OLAPConnectionString" connectionString="Data Source=.;Initial Catalog=myCube";Locale Identifier=1033/>

    Connect上的參考

    環境:
    SSAS 2008R2  Standard Edition CU6 英文版
    Windows 7 64 bit 繁體中文版
    Office 2010 64 bit 繁體中文版

    IE9更改搜尋提供者網址

    重灌了電腦安裝IE9, 加入了google做為預設的搜尋提供者,
    搜尋時,google左邊的功能選項的網路中,我一直慣用先找台灣的網頁,但卻沒出現?
    只有簡體中文和繁體中文網頁可選擇.

    想要去更改搜尋提供者的網址,但卻找不到地方可設定?

    找到這篇教學..雖然是IE8的設定,但IE9也是可適用

    因為我只有設google一個搜尋提供者,所以就直接開regedit找到機碼
    \\HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchScopes\

    底下應只有二個機碼,找到一個里頭有URL的, 把
    http://www.google.com/search?hl=zh-tw&q={searchTerms}

    改成有帶.tw的網址就好了...

    http://www.google.com.tw/search?hl=zh-tw&q={searchTerms}

    我就是要台灣網頁啦..

    2011年4月11日 星期一

    Windows 7 的隱藏共用權限

    一個舊系統安裝到Windows 7的環境後,原本有個隱藏資料夾無法寫入檔案了.

    在windows XP環境下, 系統安裝後一直沒有這個問題,

    一時之間我也找不到解決方法,只好一一叫使用者把隱藏目錄改成一般共用資料夾開啟可讀寫的權限..

    直到今天,無意中看到這篇KB....才知道要去哪里設定....Orz

    簡單來說,就是我的電腦按滑鼠右鍵選管理,進入電腦管理後,在共用資料\共用下找到隱藏目錄後,再按滑鼠右鍵選內容,將其共用權限改成完全變更即可

    2011年4月7日 星期四

    轉貼...Database Mail 送出html tabular 郵件

    之前用FOR XML PATH組出一個COLUMN多筆資料變成一筆...

    這次再次見識他的強大...

    Send email in a tabular format using SQL Server database mail


    Database Mail設定
    sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'Database Mail XPs', 1;
    GO
    RECONFIGURE
    GO

    -- Create a Database Mail account
      EXECUTE msdb.dbo.sysmail_add_account_sp
     @account_name = 'Bev',
     @description = 'Mail account for test e-mail.',
     @email_address = 'test@test.com',
     @replyto_address = null,
     @display_name = 'Beverly',
     @mailserver_name = 'test.com' ;
     
      -- Create a Database Mail profile
     EXECUTE msdb.dbo.sysmail_add_profile_sp
     @profile_name = 'Hinet',
     @description = 'Profile used for test mail.' ;
     
      -- Add the account to the profile (一個profile可有多個account)
     EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
     @profile_name = 'Hinet',
     @account_name = 'Bev',
     @sequence_number =1 ;
     
     
      -- Grant access to the profile to the DBMailUsers role
     EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
     @principal_name = 'public',
     @profile_name = 'Hinet',
     @is_default = 1 ;



     

    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 參數。

    2011年2月20日 星期日

    asp.net menu 和 flash

    在aspx上放了一個falsh object , 瀏覽時卻發現原本的sitemap menu下拉時, 卻被蓋在falsh下,
    一直都把焦點放在z-index的修改上
    看到 Tsung's Blog ...哈哈, 我也恍然大悟了. 感謝他

    主要是在flash object加入一個設定

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%"
            codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0">
            <param name="MOVIE" value="../Yoshinoya/BrandSingleSeason.swf">
            <param name="PLAY" value="true">
            <param name="LOOP" value="true">
            <param name="WMODE" value="transparent">
            <param name="QUALITY" value="high">
            <embed src="BrandSingleSeason.swf" width="100%" height="100%" play="true" loop="true"
                wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
        </embed>
        </object>

    另外,由Tsung's Blog延伸找到的範例也有詳細的說明 Z-Index and Flash.


    後來,又查得JQuery提供一個swf plugin的套件,使用這個插件就無menu被蓋住的問題了.
    所以後來參考範例網站後,就改用這個方式 ,程式碼也很簡潔

        <script type="text/javascript" src="../Scripts/jquery.swfobject.1-1-1.min.js"></script>     
        <script type="text/javascript">
            function displayFlash(type) {
                $('#myFlash').flash({ swf: type, height: '100%', width: '100%' });
            }
        </script> 
        <div id="myFlash" >
        </div>

    進階的使用方法可參考

    jQuery SWFObject Plugin

    2011年2月9日 星期三

    取用BugNet的HtmlEditor Provider

    在BugNet Issue維護中,Descriptioncomment是使用html編輯器的方式讓我們可以輸入html格式的文字,我覺得挺好用的.

    在BugNet的source code查看這段的做法,發現是利用provider的方式做的,先把相關的srouce code 抽出來,試著放入自已專案用的程式碼中

    1.下載最新的BugNet souce code, 目前版本是0.8.276.0, 解壓縮後,複製以下目錄
     \BugNET-0.8.276-Source\src\Library\Providers\HtmlEditorProviders 

    2.建立一個新方案,把 \BugNET-0.8.276-Source\src\Library\Providers\HtmlEditorProviders\下的四個專案都加入, 如果有需要,可以修改一下專案的Assembly Name及相關的namespace,不然build出來的dll名稱會是BugNet開頭的dll

    3.build 完後,分別將專案內的dll複製出來,add reference 到自已的website 專案中,
    同時也複製 以下目錄檔案及檔案

     a. \BugNET-0.8.276-Source\src\BugNET_WAP\Providers\HtmlEditorProviders
     b. \BugNET-0.8.276-Source\src\BugNET_WAP\UserControls\HtmlEditor.ascxHtmlEditor.ascx.cs、HtmlEditor.ascx.designer.cs

    3.開啟自已website專案的web.config檔, 加入以下

     <configSections>
    <section name="HtmlEditorProvider" type="BugNET.Providers.HtmlEditorProviders.HtmlEditorConfiguration, BugNET.Providers.HtmlEditorProviders" requirePermission="false" allowDefinition="MachineToApplication" />
     </configSections>


    <HtmlEditorProvider defaultProvider="CkHtmlEditorProvider">
        <providers>
          <add name="TextboxHtmlEditorProvider" type="BugNET.Providers.HtmlEditorProviders.TextboxHtmlEditorProvider, BugNET.Providers.TextboxHtmlEditorProvider" Height="250" Width="100%" />
          <add name="FckHtmlEditorProvider" type="BugNET.Providers.HtmlEditorProviders.FckHtmlEditorProvider, BugNET.Providers.FckHtmlEditorProvider" Height="250" Width="100%" ToolbarSet="Default" Skin="Silver" providerPath="~\Providers\HtmlEditorProviders\fckeditor\" />
          <add name="CkHtmlEditorProvider" type="BugNET.Providers.HtmlEditorProviders.CkHtmlEditorProvider, BugNET.Providers.CkHtmlEditorProvider" Height="250" Width="100%" Toolbar="Basic" providerPath="~\Providers\HtmlEditorProviders\CKEditor\" />
        </providers>
      </HtmlEditorProvider>


    <pages enableSessionState="true" theme="Default">
          <controls>
              <add tagPrefix="bn" tagName="HtmlEditor" src="~/UserControls/HtmlEditor.ascx" />
     </controls>
        </pages>


    以上紅字部份是依自已的需求做更改的

    4.建立一個測試網頁testHtmlEditor.aspx
    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="testHtmlEditor.aspx.cs" Inherits="Issues.testHtmlEditor" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        test
      <bn:HtmlEditor id="EditCommentHtmlEditor" Height="200" runat="server" />       
    </asp:Content>

    執行後就可以看到html editor元件了.

    BugNet預設的html editor toolbar是使用"Basic", 這個定義你可在
    \BugNET-0.8.276-Source\src\BugNET_WAP\Providers\HtmlEditorProviders\CKEditor\config.js 自行修改,以下是原本的定義
    config.toolbar_Basic =
    [   
        ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
        ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],   
        '/',
        ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
        ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
        ['BidiLtr', 'BidiRtl' ],
        ['Link','Unlink','Anchor'],
        ['Image','Table','HorizontalRule'],
        '/',
        ['Styles','Format','Font','FontSize'],
        ['TextColor','BGColor'],
        ['Maximize', 'ShowBlocks','-','About']
    ];


    BugNet中還有不少可學習的點,沒什麼想法的人可以玩看看

    2011年1月13日 星期四

    sp_MSforeachdb and sp_MsForEachTable

    看到MSSQLTips 上這篇文章,

    Making a more reliable and flexible sp_MSforeachdb

    測試了一下發現挺實用,可以自由發揮

    --instance中所有DB
    exec sys.sp_MSforeachdb 'select ''?'' ' 


    --instance中所有DB空間使用狀況
    exec sys.sp_MSforeachdb'use ?; exec sp_spaceused'


    --instance中所有DB訊息
    exec master.sys.sp_MSforeachdb'use ?; exec sp_helpdb ? '

    --目前DB中所有table訊息(含資料結構)
    exec sys.sp_MsForEachTable 'sp_help ''?'' '


    --目前DB中所有table筆數
    exec sys.sp_MsForEachTable 'select ''?'', count(*) from ? '


    其中傳入的變數 ?是否要當字串或欄位或物件,就依平常我們直接select 時的想法去想就可以明白了
    要當字串,則前後加單引號, 要當物件則直接使用? 或[?] 都可以

    2011年1月11日 星期二

    DSOFramer @ windows 2008 R2 64bit

    作業系統即將升級到Windows 2008 R2 + SQL 2005 64 bit + Office 2007 ,所以做了測試

    網站上需要產生Excel檔,然後開啟做線上檢視

    使用DSOFramer ActiveX元件是最方便的檢視元件


    產生Excel是用Excel Application的方式實做,測試後發生太多奇奇怪怪的問題,大都是和Excel開檔的權限有關。
    大家都覺得測的很煩了,所以請同事改用NPOI的方式重新撰寫這一段產生Excel套表的程式碼。

    ps.使用NPOI時,若是office 2003則需要上到SP2以上,不然有時會無法在DSOFramer上開檔

    完成後,終於可以順利產生Excel檔了,但用DSOFramer OpenWebDoc (open url doc)時,出現了這個錯誤訊息
    The associated COM server does not support ActiveX Document embedding.

    爬了文後,有人說在open時,要給定第三個參數 "Word.Document"

    像這樣   open "http://test/xls/test.xls" , true, "Word.Document"

    試了一下,結果改出現這個錯誤訊息
    程序呼叫或引數不正確

    然後開啟來的竟是word 的檔案轉換程式?

    最後參考這篇文章,把參數改成 "Excel.Sheet"

    Visual C++ ActiveX Control for hosting Office documents in Visual Basic or HTML


    像這樣  open "http://test/xls/test.xls" , true, "Excel.Sheet"

    然後就可以正常顯示了。LUCKY。。。

    原來這是office 的program id表列如下,

     Excel Spreadsheet     "Excel.Sheet"    
      Excel Chart     "Excel.Chart"       
      PowerPoint Presentation   "PowerPoint.Show"  
      Project Database    "MSProject.Project" 
      Visio Drawing    "Visio.Drawing"   
      Word Document    "Word.Document"  

    publish error allowDefinition='MachineToApplication'

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