惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - 冰冷

经典正则表达式 (转) 常用的javascript小技巧[作者oror][转] HR 事务代码 (转) rp-provide-from-last 给SAP系统安装联机帮助(事务码SR13) (转) - 冰冷 - 博客园 如何修改 SAP 登录后的背景图片(事务码 SMW0,SM30)(转) 导出txt文件简单的例子 sapgui640免除每次登录都要输入密码(转) 关于MiPlatform310 关于oracle form开发中commit WHEN-VALIDATE-ITEM 和 KEY-NEXT-ITEM两个trigger 的先后顺序 vs2005中的treeview 关于给winform的DataGrid中添加复选框的问题 用.NET创建windows服务 google中的超强搜索 关于FAT32 -> NTFS 文件系统转换 数据库连接字符串大全 [TrackBack] 转自CSDN 地址:http://blog.csdn.net/gauss32/archive/2004/10/27/154621.aspx 关于配置证书服务器,和自己颁发企业证书 自动日志组件 - Log4net应用(转贴来自http://dotnet.3yee.com/)
VS2005 写存储过程
冰冷 · 2006-07-18 · via 博客园 - 冰冷

刚转到VS2005和SQL2005上,研究了一下怎么在vs2005中写存储过程
以下是我写的代码
首先新建一个

确定之后会让你选择数据联结

如果默认的数据库没有,可以用add refrence添加

之后再在解决方案中添加一个StoredProcedure项目
下面是代码
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Data.Sql;

public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    [SqlProcedure]
    public static void Hello()
    {
        SqlContext.Pipe.Send("hello ,fypoop!");
       
    }

    [SqlProcedure]
    public static void InsertData(SqlString name)
    {
        
       using (SqlConnection conn = new SqlConnection("context connection=true"))
  {
   conn.Open();
   SqlCommand cmd = new SqlCommand();
   cmd.CommandType = CommandType.Text;
   cmd.Connection = conn;
   cmd.CommandText = "INSERT INTO BIProperty ([Type], [Count],[Desc]) VALUES ('" + name.Value + "',1, '" + DateTime.Now.ToString() + "')";  
      cmd.ExecuteNonQuery();
  }
        
    }

    [SqlFunction]
    public static SqlString testFunction()
    {
        return "hello , fypop.cnBlogs.com";
    }

    [SqlProcedure]
    public static void GetTitlesByAuthor(string flag)
    {
        string sql = "select * from AnswerContentAndScore where flag=@flag";
        using (SqlConnection conn = new SqlConnection("context connection=true"))
        {
            conn.Open();
            SqlPipe sp = SqlContext.Pipe;
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = conn;
            cmd.CommandText = sql;
            SqlParameter paramauthorID = new SqlParameter("@flag", SqlDbType.Int);
            paramauthorID.Direction = ParameterDirection.Input;
            paramauthorID.Value = flag;
            cmd.Parameters.Add(paramauthorID);
            SqlDataReader rdr = cmd.ExecuteReader();
            sp.Send(rdr);
        }

    }
};

说明
SqlConnection("context connection=true")是表示用当前登录SQL Server的用户来开连接,进行操作
SqlContext 从服务器端把消息,结果集返回到客户端

这时候你就可以用EXEC SqlProcedure 来跑你自己的存储过程了
理解有限,所以写的也有限,大家看看就好了

忘了说一点,如果你的SQL2005服务器不支持clr ,那就运行一下下面的存储过程
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO 
 
 EXEC sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO 

要关闭clr enabled,可以使用

EXEC sp_configure 'clr enabled', 0
GO
RECONFIGURE
GO