Enumtables/EnumColumns from DMO

  • Thread starter Thread starter nigel
  • Start date Start date
N

nigel

can anyone provide an example of how to use the Enumtables methods in SQL
DMO from VB.Net ?

(I want to be able to get back the tables and schema from a linked server)

tia
 
Cheers but still not found anything (but then a google for Enumtables didnt
give anything useful hence my original posting)..... perhaps I'll just say
s*d it and see what SQL-SMO brings and whether theres anything new in the
box....
 
Cheers but still not found anything (but then a google for Enumtables
didnt give anything useful hence my original posting)..... perhaps I'll
just say s*d it and see what SQL-SMO brings and whether theres anything
new in the box....

Below is a VB.Net example that uses DMO. Like you, I look forward to SMO.


Public Function GetTableList( _
ByVal SqlServerName As String, _
ByVal LinkedServerName As String) As DataTable

Try
'connect to SQL Server
Dim sqlServer As New SQLDMO.SQLServer2
sqlServer.LoginSecure = True
sqlServer.Connect(SqlServerName)

'get linked server
Dim linkedServer As New SQLDMO.LinkedServer2
linkedServer = sqlServer.LinkedServers.Item(LinkedServerName)

'get table list and transform to DataTable
Dim queryResults = linkedServer.EnumTables

'transform table list to a DataTable
Dim rowNumber As Integer, columnNumber As Integer
Dim dataTable As New DataTable
For columnNumber = 1 To queryResults.Columns
dataTable.Columns.Add( _
New DataColumn(queryResults.ColumnName(columnNumber)))
Next columnNumber
For rowNumber = 1 To queryResults.Rows
For columnNumber = 1 To queryResults.Columns
dataTable.Rows.Add(dataTable.NewRow())
dataTable.Rows(rowNumber - 1)(columnNumber - 1) = _
queryResults.GetColumnString(rowNumber, columnNumber)
Next columnNumber
Next rowNumber

'cleanup
linkedServer = Nothing
sqlServer.Close()
sqlServer = Nothing

Return dataTable 'table list as DataTable

Catch ex As Exception
Throw New ApplicationException("GetTableList failed: " +
ex.ToString())
End Try
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SQL-DMO and VB.Net 1
get create table script for a SQL Server object 3
binding to datagridview 1
>> getting info from sql server 1
SQL-DMO ?? 4
SQL-DMO 4
database layer 3
SQL Server Management Objects (SMO) 4

Back
Top