2021年12月21日 星期二

[.net] 檢查Server安裝.net 版本

 


檢查server上安裝的.net framework版本



cd C:\Windows\System32

dir %WINDIR%\Microsoft.Net\Framework\v* O-N /B




檢查server上安裝的.net core版本

dotnet --list-sdks




參考 https://docs.microsoft.com/zh-tw/dotnet/core/install/how-to-detect-installed-versions?pivots=os-windows



2021年9月1日 星期三

[MSSQL] 預存程序引用DLL參考



*在組件中加入DLL參考



*可將DLL檔案轉成bytes 直接加入參考



CREATE ASSEMBLY SQLCom

FROM 0x4D5A900003.................

WITH PERMISSION_SET = SAFE;



DLL to bytes string 參考

https://stackoverflow.com/questions/2885335/clr-sql-assembly-get-the-bytestream





 *DLL程式碼


    [Microsoft.SqlServer.Server.SqlFunction]

    public static string GZip(string rawString)

    {

       ..................

            return (string)(Convert.ToBase64String(zippedData));

    }








    * 於資料新增 擴充的 預存程序

    CREATE FUNCTION dbo.GZip(@src nvarchar(MAX))

    RETURNS nvarchar(MAX)

    EXTERNAL NAME SQLCom.UserDefinedFunctions.GZip





*SQL指令
    SELECT dbo.GZip(S_String)




2021年1月25日 星期一

[C#] 利用svcutil.exe下指令產生WCF client端的程式碼

 


在做異質系統間接時,若是透過WCF連線,此時專案就必須加入服務參考,但開發本機端若因為防火牆因素無法直接連到對方的WCF服務來取的服務參考,但目標機器又無法安裝VS2019開發工具,這時可在目標機器上安裝SDK,並利用svcutil.exe來下指令產生clinet端程式碼


以下兩道指令

svcutil.exe /t:metadata http://******/******/MsgService.svc

svcutil *.wsdl *.xsd /language:cs /out:MsgService.cs /config:app.config




2020年6月2日 星期二

[win10] 在Windows 10中以 系統管理員身分

擷取自:https://walker-a.com/archives/5966

參考:https://marcus116.blogspot.com/2018/12/how-to-run-visual-studio-as-administrator-by-default.html




方法:捷徑上指定系統管理員身分為預設的執行權限
在捷徑上按下滑鼠右鍵並選擇「內容」。

【捷徑】分頁畫面上按下〔進階〕。
在〔進階〕內容的畫面上勾選「以系統管理員身分執行」,並按下〔確定〕來離開。


如果出現以下拒絕存取的對話框,請點選〔繼續〕按鈕來完成。


你也可以使用【相容性】分頁上的「以系統管理員身分執行此程式」。

2020年1月3日 星期五

[windows] 控制win10更新時間或停止更新


參考 https://www.bnext.com.tw/article/48840/turn-down-win-10-update

為了掌控windows自動更新自動重開機,必須設定的



在搜尋框內輸入「編輯群組原則」
透過左側的目錄樹轉到「電腦設定 – 系統管理範本 - Windows 元件 - Windows Update」找到「設定自動更新」選項














2019年7月29日 星期一

[windows] 允許多人遠端磚面連線


轉自:https://is.gd/iA0dzF



預設情況下,同一個帳號,只能一個連線,如果建立新的連線,舊的連線會被斷線

以下是開放的方式:

執行 【gpedit.msc】



【電腦設定】->【系統管理範本】->【Windows元件】

>【遠端桌面服務】->【遠端桌面工作階段主機】->【連線】

在右邊的視窗,找到【限制遠端桌面服務的使用者只能使用一個遠端桌面服務工作階段】,預設是【尚未設定】

改成【已停用】




2019年4月4日 星期四

[C#] 用CLR讓 SQL 可以用GZIP壓縮字串


C#  程式碼







     
        /// <summary>
        /// 将传入字符串以GZip算法压缩后,返回Base64编码字符
        /// </summary>
        /// <param name="rawString">需要压缩的字符串</param>
        /// <returns>压缩后的Base64编码的字符串</returns>
        public static string GZip(string rawString)
        {
            return rawString;   //off test
            if (string.IsNullOrEmpty(rawString) || rawString.Length == 0)
            {
                return "";
            }
            else
            {
                byte[] rawData = System.Text.Encoding.UTF8.GetBytes(rawString.ToString());
                byte[] zippedData = GZip_Compress(rawData);
                return (string)(Convert.ToBase64String(zippedData));
            }

        }
        /// <summary>
        /// GZip压缩
        /// </summary>
        /// <param name="rawData"></param>
        /// <returns></returns>
        public static byte[] GZip_Compress(byte[] rawData)
        {
            MemoryStream ms = new MemoryStream();
            GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true);
            compressedzipStream.Write(rawData, 0, rawData.Length);
            compressedzipStream.Close();
            return ms.ToArray();
        }
        /// <summary>
        /// 将传入的二进制字符串资料以GZip算法解压缩
        /// </summary>
        /// <param name="zippedString">经GZip压缩后的二进制字符串</param>
        /// <returns>原始未压缩字符串</returns>
        public static string UnGZip(string zippedString)
        {
            return zippedString;   //off test
            if (string.IsNullOrEmpty(zippedString) || zippedString.Length == 0)
            {
                return "";
            }
            else
            {
                byte[] zippedData = Convert.FromBase64String(zippedString.ToString());
                return (string)(System.Text.Encoding.UTF8.GetString(UnGZip_Decompress(zippedData)));
            }
        }
        /// <summary>
        /// ZIP解压
        /// </summary>
        /// <param name="zippedData"></param>
        /// <returns></returns>
        public static byte[] UnGZip_Decompress(byte[] zippedData)
        {
            MemoryStream ms = new MemoryStream(zippedData);
            GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Decompress);
            MemoryStream outBuffer = new MemoryStream();
            byte[] block = new byte[1024];
            while (true)
            {
                int bytesRead = compressedzipStream.Read(block, 0, block.Length);
                if (bytesRead <= 0)
                    break;
                else
                    outBuffer.Write(block, 0, bytesRead);
            }
            compressedzipStream.Close();
            return outBuffer.ToArray();
        }
 







產生SQL共用函式

-----------------------1.set SQL Server可執行CLR-----------------------
sp_configure 'clr enabled', 1
GO
RECONFIGURE
go

-----------------------2.建立ASSEMBLY-----------------------

CREATE ASSEMBLY Net_SQLCom  FROM '******\bin\Debug\SQLCom.dll'
WITH PERMISSION_SET = SAFE;
--drop ASSEMBLY Net_SQLCom
go

--chk  有沒有看到Net_SQLCom
SELECT * FROM sys.assemblies
go

-----------------------3.建立function-----------------------
--drop function GZip
--drop function UnGZip

CREATE FUNCTION [dbo].[GZip](@str [nvarchar](max) )
RETURNS [nvarchar](MAX) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [Net_SQLCom].[UserDefinedFunctions].[GZip]
GO


CREATE FUNCTION [dbo].[UnGZip](@str [nvarchar](max) )
RETURNS [nvarchar](MAX) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [Net_SQLCom].[UserDefinedFunctions].[UnGZip]
GO

--chk  有沒有看到function
SELECT * FROM sys.assembly_modules;

-----------------------4.Test-----------------------
select [dbo].[UnGZip]([dbo].[GZip]('setse' ))





注意資料庫型別

char資料有固定長度,並且都為英文數字。
nchar資料有固定長度,但不確定是否皆為英文數字。
varchar資料沒有固定長度,並且都為英文數字。
nvarchar資料沒有固定長度,且不確定是否皆為英文數字。

[C#] 產生DLL給MS SQL引用



建置CLR 使用者定義函式,產出DLL給MS SQL 會出現錯誤

CREATE ASSEMBLY 失敗,因為組件是針對不支援的 Common Language Runtime 版本所建立的

此時可使用  .NET  3.5 編譯即可



環境 VS 2015
MS SQL 2008 R2


CLR建置方法參考:

如何在SQL Server中加入 C# CLR Function:
https://www.uuu.com.tw/Public/content/article/18/20180402.htm

https://dotblogs.com.tw/rockchang/2016/06/07/141319




2019年1月1日 星期二

[C#] 取得檔案路徑相關資訊



參考:http://rojerchen.blogspot.com/2013/02/c.html


            string file = @"d:\abc\123.txt";

            //string file = @"d:\abc\";

            string s0 = Path.GetFileName(file); //取得完整檔名 > 123.txt

            string s1 = Path.GetFileNameWithoutExtension(file); //取得檔案名,不包含副檔名,本例得到 123
           
            string s2 = Path.GetExtension(file); //取得副檔名 txt

            string s3 = Path.GetPathRoot(file); //取得根目錄 d:\a

            string s4 = Path.GetFullPath(file); //取得路徑 d:\abc\123.txt



2018年12月24日 星期一

[Android] google 地圖 沒有網路連線


解法參考 https://goo.gl/7p3YQh



小米收機在行動網路4g的環境下

打開 Google Map 地圖,會一直出現沒有網路連線,並且不能搜尋路徑

但是在wifi環境下是正常的

這時候 點開設定=>個人內容=>
嘗試關閉 [網路和應用程式活動] 
[時間軸電子郵件]
[google 相簿]
[在你的個人資料上顯示你所發布的內容]

大概是某個設定裡頭的資料紀錄有bug導致的,可嘗試關閉看看



 

MangoHost Copyright © 2009 Cookiez is Designed by Ipietoon for Free Blogger Template