zoukankan      html  css  js  c++  java
  • sql2005 clr例子

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data.SqlTypes;
    using System.Text.RegularExpressions;
    using Microsoft.SqlServer.Server;
    using System.Net;
    using System.IO;
    namespace qanholas
    {
    public class net
    {
    [SqlFunction(IsDeterministic
    = true, DataAccess = DataAccessKind.None)]
    public static SqlString ping(string html)
    {
    return (SqlString)GetWebClient(html);
    }


    private static string GetWebClient(string url)
    {
    string strHTML = "";
    WebClient myWebClient
    = new WebClient();
    Stream myStream
    = myWebClient.OpenRead(url);
    StreamReader sr
    = new StreamReader(myStream, System.Text.Encoding.GetEncoding("utf-8"));
    strHTML
    = sr.ReadToEnd();
    myStream.Close();
    return strHTML;
    }



    }


    }
     
    --创建程序集 
    USE qanholas; 
    CREATE ASSEMBLY qanholas  
    FROM 'D:\WindowsApplication\qanholas\qanholas\bin\Debug\qanholas.dll' 
     
     
    --创建函数 
    CREATE FUNCTION dbo.gethtml 

        @html AS NVARCHAR(20

    RETURNS NVARCHAR(MAX
    AS 
        EXTERNAL NAME qanholas.[qanholas.net].[ping]; 
    GO 
     
     
    --无限制访问 
    USE [qanholas] 
    GO 
     
    ALTER ASSEMBLY [qanholas] 
    WITH PERMISSION_SET = UNSAFE 
     
    GO 
     
     
     
    SELECT dbo.gethtml('http:\\www.baidu.com')  
  • 相关阅读:
    Bessie Goes Moo
    小P的强力值
    Max Flow
    约瑟夫
    Moocryption
    杂务
    排行榜
    银行贷款
    轰炸
    Contaminated Milk
  • 原文地址:https://www.cnblogs.com/qanholas/p/2097173.html
Copyright © 2011-2022 走看看