Having the Result Set of a Stored Proc Sent to You by RSS Feed.

by JBrooks   14. 十二月 2010 12:44

I wanted to monitor one of my system from my desk top and from my phone.  I found a simple solution whereby I can subscribe to the result set of a stored proc by using RSS. So I can have this feed MS Outlook, my phone or my web browser.

First, Visual Studio 2010 makes creating an RSS feed a simple matter that is about 1 page of code.

I simply add an ASPX page to my project and remove most of the markup so it only has 2 lines:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="rss.aspx.cs"  Inherits="RSS.rss"  %>

 

<%@ OutputCache Duration="60" VaryByParam="none" %>

Next the code behind simply calls the stored proc placing the results into a table and then loading up some of the RSS related collections VS2010 gives you.

 

using System;

using System.Data;

using System.ServiceModel.Syndication;

using System.Web;

using System.Collections.Generic;

using System.Xml;

 

namespace RSS

{

public partial class rss : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

        string id = Request.QueryString["id"];

 

        // I don't want just anyone to subscribe, so you have to know the GUID.

        if (id== null || id != "23F14EA1-1B20-443B-9B94-92C4EA4A8099")

            throw new Exception("Guid not reconized");

 

 

        Response.ContentType = "application/atom+xml";

 

        // this gets the data from the database and populates a table.

        DataTable dt = cDB.getFeed();

        SyndicationFeed myFeed = new SyndicationFeed();

 

        myFeed.Title = TextSyndicationContent.CreatePlaintextContent("SampleApp Activity");

        myFeed.Description = TextSyndicationContent

            .CreatePlaintextContent(@"A syndication of the most recently 

                    SampleApp activity including exceptions.");

        myFeed.Links.Add(SyndicationLink.CreateAlternateLink(

            new Uri(GetFullyQualifiedUrl("/rss.aspx"))));

        myFeed.Links.Add(SyndicationLink.CreateSelfLink(

            new Uri(GetFullyQualifiedUrl(Request.RawUrl))));

        myFeed.Copyright = TextSyndicationContent

                        .CreatePlaintextContent("Copyright SampleApp");

        myFeed.Language = "en-us";

 

 

        List<SyndicationItem> feedItems = new List<SyndicationItem>();

        foreach (DataRow dr in dt.Rows)

        {

 

            SyndicationItem item = new SyndicationItem();

            item.Title = TextSyndicationContent.CreatePlaintextContent(dr["title"].ToString());

            SyndicationPerson authInfo = new SyndicationPerson();

            authInfo.Email = "SampleApp@YourDomain.com";

 

            item.Authors.Add(authInfo);

            // RSS feeds can only have one author.

 

            // The stored proc returns different categories of data that I am interested in.

            switch (dr["category"].ToString())

            {

                case "WindFarms":

                case "WindFarms ":

                    item.Links.Add(SyndicationLink.CreateAlternateLink(

                        new Uri(GetFullyQualifiedUrl("/WindFarms.aspx"))));

                    authInfo.Name = "SampleApp WindFarm";

                    break;

 

                case "Exceptions":

                    item.Links.Add(SyndicationLink.CreateAlternateLink(

                        new Uri(GetFullyQualifiedUrl("/ErrorLog.aspx"))));

                    authInfo.Name = "SampleApp Exception";

                    break;

 

                default:

                    authInfo.Name = "SampleApp";

                    break;

 

            }

            item.Summary = TextSyndicationContent.CreatePlaintextContent(

                dr["summary"].ToString());

 

            item.Categories.Add(new SyndicationCategory(dr["category"].ToString()));

            item.PublishDate = DateTime.Parse(dr["pubdate"].ToString());

            item.LastUpdatedTime = item.PublishDate;

            item.Id = item.PublishDate.ToString();

 

            // Add the item to the feed

            feedItems.Add(item);

        }

 

 

        myFeed.Items = feedItems;

 

 

        XmlWriter feedWriter = XmlWriter.Create(Response.OutputStream);

 

        // Use Atom 1.0 

        Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(myFeed);

        atomFormatter.WriteTo(feedWriter);

 

        feedWriter.Close();

 

    }

 

    private string GetFullyQualifiedUrl(string s)

    {

        Uri u = new Uri(HttpContext.Current.Request.Url, s);

        return u.ToString();

 

    }

 

}

}

To have this feed my Outlook RSS folder I just need to right click “RSS Feeds” and select “Add a New RSS Feed…”.

Then enter the URL of my RSS feed.   Don’t forget to add the GUID at the end with     ?id=23F14EA1-1B20-443B-9B94-92C4EA4A8099

If you site uses authentication in your site you will have to turn it off for the rss.aspx page.  To do this you would add an entry in your web config file:

 

<location path="rss.aspx">

    <system.web>

        <authorization>

            <allow users="*"/>

        </authorization>

    </system.web>

</location>

You should now have a folder in Outlook that will get populated by the feed.

Having the Result Set of a Stored Proc Sent to You by RSS Feed.的更多相关文章

  1. MySQL5.7: Paging using Mysql Stored Proc

    -- 查询外键 涂聚文 (Geovin Du) select concat(table_name, '.', column_name) as 'foreign key', concat(referen ...

  2. Creating a SharePoint BCS .NET Connectivity Assembly to Crawl RSS Data in Visual Studio 2010

    from:http://blog.tallan.com/2012/07/18/creating-a-sharepoint-bcs-net-assembly-connector-to-crawl-rss ...

  3. [转]How to get return values and output values from a stored procedure with EF Core?

    本文转自:https://stackoverflow.com/questions/43935345/how-to-get-return-values-and-output-values-from-a- ...

  4. [转]SSIS Execute SQL Task : Mapping Parameters And Result Sets

    本文转自:http://www.programmersedge.com/post/2013/03/05/ssis-execute-sql-task-mapping-parameters-and-res ...

  5. Support for multiple result sets

    https://blueprints.launchpad.net/myconnpy/+spec/sp-multi-resultsets Calling a stored procedure can p ...

  6. Using Stored Programs with MySQLdb

    http://flylib.com/books/en/1.142.1.125/1/ Using Stored Programs with MySQLdb The techniques for call ...

  7. [转]Entity Framework Sprocs with Multiple Result Sets

    本文转自:https://msdn.microsoft.com/en-us/data/jj691402.aspx Entity Framework Sprocs with Multiple Resul ...

  8. Mini ORM——PetaPoco笔记

    Mini ORM--PetaPoco笔记 记录一下petapoco官网博客的一些要点.这些博客记录了PetaPoco是如何一步步改进的. 目录: Announcing PetaPoco PetaPoc ...

  9. Mini ORM——PetaPoco笔记(转)

    记录一下petapoco官网博客的一些要点.这些博客记录了PetaPoco是如何一步步改进的. 目录: Announcing PetaPoco PetaPoco-Improvements PetaPo ...

随机推荐

  1. poj-2376 Cleaning Shifts (排序+贪心)

    http://poj.org/problem?id=2376 john有n头牛做打扫工作,他想在t时间内每个时间都至少有一头牛在做打扫工作,第一头牛在1,最后一头牛在t时间,每一头牛工作都有一个开始时 ...

  2. 第三方登录(1)OAuth(开放授权)简介及授权过程

    3个角色:服务方,开发者,用户 a.用户在第在服务注册填写个人信息, b.服务方开放OAuth, c.开发者在服务方申请第3方登录,在程序中得到令牌后,经用户同意,可得到用户的个人信息. OAuth ...

  3. MySQL之Join

    参见MySQL(以5.1为例)中官方手册:MySQL官方手册-JOIN 假设有以下几个表 t1 id book 1 java 2 c++ 3 php t2 id author 2 zhang 3 wa ...

  4. 手机号段、ip地址归属地大全,最新手机号段归属地,IP地址归属地数据库

    百事通:http://www.114best.com/dh/114.aspx?w=17097232323,联通识别为电信的,1349错 二三四五:http://tools.2345.com/frame ...

  5. Android 实现布局动态加载

    Android 动态加载布局 通过使用LayoutInflater 每次点击按钮时候去读取布局文件,然后找到布局文件里面的各个VIEW 操作完VIEW 后加载进我们setContentView 方面里 ...

  6. Tomcat,Jboss,Glassfish等web容器比较选型

    概述 Web容器是一种服务调用的规范,J2EE运用了大量的容器和组件技术来构建分层的企业应用.在J2EE规范中,相应的有WEB Container和EJB Container等. Web容器给处于其中 ...

  7. CSS之弧形阴影

    简述 网页上经常会出现一些弧形的阴影效果,看起来很漂亮,下面我们来讲述下如何用CSS来实现一个弧形阴影. 简述 阴影 效果 注释 标题 效果 源码 合并 效果 源码 阴影 效果 首先实现一个简单的阴影 ...

  8. 转:Emmet:快速编写HTML,CSS代码的有力工具

    http://www.cnblogs.com/xiazdong/p/3562179.html  试着用用

  9. Dom文档模型

    文档对象模型     通过 JavaScript,您可以重构整个 HTML 文档.您可以添加.移除.改变或重排页面上的项目.要改变页面的某个东西,JavaScript 就需要获得对 HTML 文档中所 ...

  10. kdtree备份

    库在这里 这个很好用. 例子: /*! gcc -Wall -g -o test test.c libkdtree.a */ #include <stdio.h> #include < ...