Return Results of sp_helptext via ADO
- From: james.igoe@xxxxxxxxx
- Date: 9 Jan 2006 09:45:26 -0800
I am trying to write code to document stored procedures for an Access
database I support. There are about 30 stored procedures on a Sybase
server that the database uses, and I am trying to write VBA using ADO
that will execute sp_helptext [stored proc name], return a recordset
to ADO, then allow me to populate a local table with the stored
procedure code.
The code I have only returns the first row of the stored procedure, and
doesn't allow me to loop (movenext) through anything.
Code:
Public Function ExportStoredProcedureText() As Boolean
On Error GoTo ErrorTrap
Dim dbCurrent As DAO.Database
Dim daorsStoredProcs As DAO.Recordset
Set dbCurrent = CurrentDb
Dim strSQLStoredProcs As String
Dim adoconnStoredProcText As ADODB.Connection
Dim adorsStoredProcText As ADODB.Recordset
Dim strSQLStoredProcBase As String
Dim strSQLStoredProcName As String
Dim strSQLStoredProcEXE As String
Dim strCurrentUser As String
Dim strConnectionString As String
Dim dcounter As Double
Dim strText As String
strSQLStoredProcBase = "EXEC sp_helptext "
' Connect to the DB
strConnectionString = GetConnectToDBString()
Set adoconnStoredProcText = New ADODB.Connection
Set adorsStoredProcText = New ADODB.Recordset
adoconnStoredProcText.Open strConnectionString
'open local table
Set daorsStoredProcs = dbCurrent.OpenRecordset("TBL_StoredProcedures",
dbOpenTable)
'for each stored procedure in table, execute sp_helptext and write to
local table
For dcounter = 0 To ((dbCurrent.TableDefs.Count) - 1)
With daorsStoredProcs
.MoveFirst
'grabs first row which is name of stored proc
strSQLStoredProcName = daorsStoredProcs(0)
'concantenates name of stored proc and command
strSQLStoredProcEXE = strSQLStoredProcBase &
strSQLStoredProcName
'returns stored proc as text
adorsStoredProcText.Open strSQLStoredProcEXE,
adoconnStoredProcText, adOpenForwardOnly
'sets stored proc text to field
daorsStoredProcs(1) = adorsStoredProcText(0)
.Update
.MoveNext
End With
Next
daorsStoredProcs.Close
Set daorsStoredProcs = Nothing
dbCurrent.Close
Set dbCurrent = Nothing
adorsStoredProcText.Close
Set adorsStoredProcText = Nothing
adoconnStoredProcText.Close
Set adoconnStoredProcText = Nothing
Exit Function
ErrorTrap:
MsgBox Err.Number & ": " & Err.Description
daorsStoredProcs.Close
Set daorsStoredProcs = Nothing
dbCurrent.Close
Set dbCurrent = Nothing
adorsStoredProcText.Close
Set adorsStoredProcText = Nothing
adoconnStoredProcText.Close
Set adoconnStoredProcText = Nothing
End Function
.
- Follow-Ups:
- Re: Return Results of sp_helptext via ADO
- From: james.igoe@xxxxxxxxx
- Re: Return Results of sp_helptext via ADO
- Prev by Date: RE: ADODB Connection.Close doesn't drop DB connection for ~60 seco
- Next by Date: Re: metadata in dataset
- Previous by thread: Re: can't get query to run over ADO, but works fine in Access interfac
- Next by thread: Re: Return Results of sp_helptext via ADO
- Index(es):
Relevant Pages
- Re: Stored Procedures & Connection Issue
... I have had to use adCmdText with MySQL stored procedures. ... Dim adoConnection
As New ADODB.Connection ... Dim SQL_hierarchy_level As String ... Dim strDatabasePathAndName
As String ... (microsoft.public.excel.programming) - Re: ADP - ADO beginner Search Records with a Sp ~ help please
... need additional stored procedures for updating/adding/deleting. ... > Dim
MyMsgBox As VbMsgBoxStyle ... >Dim cnn As ADODB.Connection ... >Set
rst = New ADODB.Recordset ... (microsoft.public.access.adp.sqlserver) - Re: Losing characters with sql parameterized insert query
... We use Stored Procedures for all of ... our database ops. ...
My guess would be that when you create a parameterized query, ... > Dim cmdSqlCommand
As SqlCommand ... (microsoft.public.dotnet.framework.aspnet) - Re: Moving User Defined Functions between Databases
... Stefan Berglund gave a great answer. ... You can include all your functions,
triggers, and stored ... user defined functions and stored procedures, ...
Dim oServer As SQLDMO.SQLServer2 ... (microsoft.public.sqlserver.programming) - Stored Procedures
... been doing all my code,, NOT using Stored procedures.. ... Public Function vLookup(ByVal
table As String, ... Dim StringToReturn As String ... Dim dataAdapter
As System.Data.OleDb.OleDbDataAdapter ... (microsoft.public.dotnet.languages.vb)