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了

2014年10月24日 星期五

windows 8 安裝sql server 2005無法啟動

為了測試需求要在windows 8安裝sql server 2005 標準版
結果安裝到一半出現錯誤
 SQL Error: 29503 — The SQL Server service failed to start

參考這篇文章,解法有點瞎,真的太瞎了....

就是裝到一半出現這個錯誤時先別急取消,
先到一台已安裝過的SQL SERVER 2005目錄下(MSSQL\Binn) 把里頭的sqlos.dllsqlserver.exe二個檔複製到正在安裝的主機目錄下,然後再按重試(RETRY)鍵,這樣就可以順利完成安裝了

安裝完畢後記得再更新到SP4。

你說 瞎不瞎啊~

IIS 網站無法下載中文檔名檔案因為取消高位元字元

 網址+中文檔案名稱方式下載檔案顯示 404 - 找不到檔案或目錄。 但英數字檔案名稱則可下載。 因為設定GCB IIS,其中1項 將高位元字元預設取消勾選了。 27 TWGCB-04-014-0028 要求篩選與其他限制模組 允許高位元字元 這項原則設定決定查詢...