Retrieve the list of SQL Server stored procedure

You can query SQL Server system tables to retrieve the list of all the stored procedure that are available for the end user and applications. The following routine extract their names and loads them in a DataGrid control:

Dim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim connString As String, sql As String' Open a connection    connString = "Provider=SQLOLEDB;Data Source=P2;Initial Catalog=Pubs"cn.Open connString, "sa", ""' Open the recordsetsql = "Select * from sysobjects where type = 'P' and category = 0"rs.Open sql, cn, adOpenStatic, adLockReadOnly, adCmdText' Load the results in a DataGrid controlSet DataGrid1.DataSource = rsDataGrid1.Refresh

The resulting Recordset contains several pieces of useful information, such as NAME (the stored procedure’s name), ID (unique identification number), and CRDATE (its creation date). To extract additional information on its arguments, however, it is necessary to query another system table:

' This code assumes that the RS recordset is corrently' pointing to the stored procedure for which you want' to extract its parametersDim rs2 As New ADODB.Recordset, sql2 As Stringsql2 = "SELECT syscolumns.Name, systypes.Name, syscolumns.length " & _    "FROM syscolumns, systypes " & "WHERE syscolumns.xtype = systypes.type AND " _    & "syscolumns.id = " & rs("ID")' open a second recordsetrs2.Open sql2, cn, adOpenStatic, adLockReadOnly, adCmdText' Assign to a second grid    Set DataGrid2.DataSource = rs2DataGrid2.Refresh

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS