I use the code below to generate a text file containing every stored
procedure and view in my SQL Server backend database, but I can't
figure out how to generate text of the User Defined Functions.
I see I can reference: SQLDMO.UserDefinedFunction
But can't find any way to reference dbs.<user defined functions>
Any help is greatly appreciated.
lq
Sub OutputDBQueries(myPath as String)
' In VB 6. Set a reference to Microsoft SQLDMO Object Library
Dim objSQLServer As New SQLDMO.SQLServer
Dim dbs As New SQLDMO.Database
Dim sp As SQLDMO.StoredProcedure
Dim v As SQLDMO.View
Dim sptext As String
objSQLServer.Connect <Servername>, <Username>, <Password>
Set dbs = objSQLServer.Databases(<Databasename>)
Open myPath For Output As #1
'>go through all stored procedures:
For Each sp In dbs.StoredProcedures
sptext = sp.Text
Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _
"************************************************* *****************************"
& _
vbCrLf & vbCrLf & vbCrLf
Next
'>go through all views:
For Each v In dbs.Views
sptext = v.Text
Print #1, sptext & _
vbCrLf & vbCrLf & vbCrLf & _
"************************************************* *****************************"
& _
vbCrLf & vbCrLf & vbCrLf
Next
MsgBox "The export is completed." & vbCrLf & vbCrLf & _
"Your export file has been created in: " & vbCrLf & _
myPath, vbInformation, "Export Completed"
End Sub