首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 网络编程-> 数据库教程
显示数据库中的存储过程__转-ASP教程,数据库相关
作者:网友供稿 点击:7
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
  
  its no easy trick to see stored procedures in a database programmatically with a scripting language like asp. if youre using ms access, youre out of luck. access provides no way to see the actual meat of a stored procedure although you can get the names of the procedures in the database with the adox.catalog com object.

but, if you are using sql server (like you should be because you care about your data), you have a guaranteed way to view all your stored procedures using two globally-available system objects: the built-in sysobjects system table and the sp_helptext system stored procedure.

with a couple of simple loops, everything about your stored procedures can be viewed and accessed programmatically in just a few lines. heres the results of the function (im allowing you to view the first few procedures only because this method can be pretty resource-intensive. if you want the complete list of procedures i use on this site, you can get it here.) heres how it looks when called:


create procedure sp_addadvertlink
(
@m1 datetime,
@m2 datetime,
@m3 varchar(20),
@m4 varchar(20),
@m5 varchar(255),
@m6 varchar(255),
@m7 varchar(255),
@m8 varchar(255)
)
as
insert into
easyads
(
display_date, display_time, display_month, display_day,
usr_ip_address, usr_browser, display_adname, usr_referer
)
values
(
@m1, @m2, @m3, @m4, @m5, @m6, @m7, @m8
)



create procedure sp_addmailrecip
(
@mipaddr varchar(255),
@memailaddr varchar(255)
)
as
insert into
autoresponder
(
ipaddress, emailaddress
)
values
(
@mipaddr, @memailaddr
)


create procedure sp_addusraddr
(
@musr varchar(255),
@mfstnme varchar(255),
@mlastnme varchar(255),
@maddr1 varchar(255),
@maddr2 varchar(255),
@mcity varchar(255),
@mstate varchar(255),
@mzip varchar(255),
@memail varchar(255),
@mphone varchar(255),
@mfax varchar(255),
@mcell varchar(255),
@mnotes text
)
as
insert into
dayplanneraddresses
(
usr, firstname, lastname, streetaddress1, streetaddress2,
city, state, zip, emailaddress, phone, fax, cell, notes
)
values
(
@musr, @mfstnme, @mlastnme, @maddr1, @maddr2, @mcity, @mstate,
@mzip, @memail, @mphone, @mfax, @mcell, @mnotes
)


------------------sysobjects.asp-------------源程序--------------

<% @ language = jscript %>
<%
with (response) {
buffer = true;
expires = 0;
clear();
}

function showprocs() {
//set-up database connection information
var connstring = application("dbconn");
var connuser = application("dbusr");
var connpass = application("dbpass");

//set this next variable to false to unrestrict the system
var limitresults = true;
var magicnumber = 2;

//get a connection
var c = new activexobject("adodb.connection");

//open database
c.open(connstring, connuser, connpass);

//enable error-trapping
try {

//attempt to access the sysobjects table.
//if you try this with ms access, you will get an error...

//sysobjects table contains information about everything
//in your database. from tables to views, and whatever in
//between, all that stuff is in the sysobjects table.

//in my db, a status of 24 indicates that its a procedure
//that i added and not one of the other bizarre stored procedures
//that were mixed in there as well. a type of p indicates stored procedure.
//other values for type can be u for user tables, r for rule,
//s for system tables (like sysobjects), tr for triggers, v for view, //etc... in this case p is the one we want.
var p = c.execute("select name from sysobjects where status = 24 and type = p order by name;");
} catch(e) {

//oops - sysobjects table not found. you must be using ms access.
//or you forgot to re-code the connection string.
response.write("this example only works with <b>sql server");
response.write("</b>. \"sysobjects\" table does not exist!<br><br>");
response.write("if you are using sql server, you may need to ");
response.write("adjust the connstring, connuser and connpass variables ");
response.write("in the showprocs( ) procedure to reflect your database\s ");
response.write("valid connection string and user account information.");

//close database connection because were leaving...
c.close();
c = null;

//quit procedure...
return;
}

//if we get here, were in the sysobjects table and ready to go.
if (limitresults) {
var i = 0;
}
while (!p.bof && !p.eof) {

//call the system stored procedure "helptext" which will return
//the exact text of the stored procedure, as entered by you...
//as a multiple recordset consisting of one field in each row.
//the name of the field is "text" and its datatype is nvarchar(255).
//each row is the equivalent of each line of the procedure as you
//entered it. for example, a procedure like this:
// create procedure sp_getitall
// as select * from table
//would return two rows when gathered with sp_helptext.
var r = c.execute("exec sp_helptext " + p.fields(0).value + "");

//check to make sure there is a record. theoretically there
//has to be at least 1 record returned since sysobjects will
//always return a "good" procedure name and not just some
//random stored procedure name.
if (!r.bof) {

//move to the top of the procedures text...
r.movefirst();
while (!r.bof && !r.eof) {

//return the procedures text...
//one line at a time.
//r.fields(0).value is also equivalent
//to the line below:
//  response.write(r("text") + "<br>");
response.write("<code style=\"font-size:9pt;font-
family:helvetica;\">" + r.fields(0).value + "</code><br>");

//move to the next line
r.movenext();
}
}

//close the sp_helptext generated recordset
r.close();
r = null;

//move to the next sysobject (in this case, the next
//stored procedure)
p.movenext();
response.write("<br>");
if (limitresults) {i++}
if (limitresults) {if (i > magicnumber) {break;}}
}

//close the sysobject recordset
p.close();
p = null;

//close the db connection
c.close();
c = null;
}
%>









<html>
<head>
  <title>the asp emporium - jscript: viewing the stored procedures in a database</title>
  <style type="text/css">
  h3 {color: #cc3300;}
  </style>
</head>
<body background="/aspemporium/pix/bg.gif" bgcolor="#eeeeee">
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr>
  <td width=50% valign=top align=left>
  <img width=283 height=36 border=0 src="/aspemporium/pix/emporium.gif"
      border=0 alt="the asp emporium">
  <br>
  <font face=verdana size=-2 color=#cc3300>
  <img width=438 height=25 border=0 src="/aspemporium/pix/blurb.gif"
      alt="free active server applications and examples by bill gearhart">
  </font>
  </td>
  <td width=50% valign=top align=right>
  <font size=-1 face=arial>
  <img width=197 height=30 border=0 src="/aspemporium/pix/online.gif"
      alt="online since friday january 7, 2000"><br>
  </font>
  </td>
</tr>
</table>
<br>
<table width=100% cellpadding=1 cellspacing=1 border=0 bgcolor=#60786b>
<tr>
  <td bgcolor=#60786b width="20%">
  <img width=195 height=20 border=0
      src="/aspemporium/pix/location.gif" alt="">
  </td>
  <td bgcolor=#ffffee width="80%">
  <font size=-1 color=#60786b face=arial>
    <!--#include virtual = "/aspemporium/inc/quicknav3.asp"-->
  </font>
  </td>
</tr>
</table>
<br>
  <table width=100% cellpadding=2 cellspacing=0 border=0>
  <tr>
    <td valign=top><!--#include virtual = "/aspemporium/inc/sidemenu_js.asp"--></td>
    <td valign=top>
    <font face="arial, verdana, helvetiva, times new roman">

    <h3>viewing the stored procedures in a database</h3>

    its no easy trick to see stored procedures in a database
    programmatically with a scripting language like asp. if youre
    using ms access, youre out of luck. access provides no way to
    see the actual meat of a stored procedure although you can get
    the <a href="/aspemporium/codelib/procs.htm">names of the procedures</a>
    in the database with the <code>adox.catalog</code> com object.
    <br>
    <br>
    but, if you are using sql server (like you should be because you
    care about your data), you have a guaranteed way to view all your
    stored procedures using two globally-available system objects:
    the built-in <code>sysobjects</code> system table and the
    <code>sp_helptext</code> system stored procedure.
    <br>
    <br>
    with a couple of simple loops, everything about your stored procedures
    can be viewed and accessed programmatically in just a few lines. heres
    the results of the function (im allowing you to view the first few
    procedures only because this method can be pretty resource-intensive. if
    you want the complete list of procedures i use on this site, you can
    <a href="/aspemporium/downloads/sql.txt">get it here</a>.) heres how
    it looks when called:
    <br>
    <br>
    <br>

    <%  showprocs();  %>

    <br>
    <br>
    <!--#include virtual = "/aspemporium/inc/jsexampleoptions.asp"-->
    </font>
    </td>
  </tr>
  </table>
</body>
</html>


文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·jsp留言板源代码4-JSP教程,数据库相关
·“脱衣秀”泛滥 四川打击淫秽色情视频聊天室
·c#中使用 crystal reports (水晶报表)的打包和部署问题-.NET教程,报表/图形/Office
·MDAC2.8 下载!-ASP教程,数据库相关
·数据库安装包的制作(参考MSDN)-.NET教程,安装和部署
·asp讲座之七:asp与数据库(二)
·深度和广度优先分油问题(C#实现)-.NET教程,C#语言
·C#在状态栏中,自绘进度条,-.NET教程,C#语言
·怎么清除sql server日志
·C#中的接口-.NET教程,C#语言
最新文章
·sql server 2005 ce基础概要_数据库教程
·用flash as代码制作按钮弹出窗口_flash教程
·alexa:戏曲性地调整_alexa排名
·google也推出域名注册_google推广
·技巧总结:div中class与id的区别及应用_css教程
·windows vista命令runas.exe全解析_windows vista
·photoshop将美女照片处理成仿古斑驳油画_photoshop教程
·百度主题推广代码的完全解析-知己知彼_网赚技巧
·你的google adsense帐号是否被人盗用?_网赚技巧
·如何挑出google adsense中单价极低的广告商_网赚技巧
相关主题
  • 显示数据库记录_visualbasic教程
  • 显示数据库中所有表及其信息-数据库专栏,SQL Server
  • 显示数据库中的表结构(新增了索引及表的描述信息)-数据库专栏,SQL Server
  • 显示数据库中的存储过程-ASP教程,数据库相关
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭