本文整理汇总了VB.NET中System.Data.SqlClient.SqlClientFactory.CreateDataSourceEnumerator方法的典型用法代码示例。如果您正苦于以下问题:VB.NET SqlClientFactory.CreateDataSourceEnumerator方法的具体用法?VB.NET SqlClientFactory.CreateDataSourceEnumerator怎么用?VB.NET SqlClientFactory.CreateDataSourceEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了SqlClientFactory.CreateDataSourceEnumerator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Module1
' 导入命名空间
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
Module Module1
Sub Main()
' List all SQL Server instances:
ListServers(SqlClientFactory.Instance)
Console.WriteLine()
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Sub ListServers(ByVal factory As DbProviderFactory)
' This procedure is provider-agnostic, and can list
' instances of any provider's servers. Of course,
' not all providers can create a data source enumerator,
' so it's best to check the CanCreateDataSourceEnumerator property
' before attempting to list the data sources.
If factory.CanCreateDataSourceEnumerator Then
Dim instance As DbDataSourceEnumerator = _
factory.CreateDataSourceEnumerator
Dim table As System.Data.DataTable = instance.GetDataSources()
Dim row As DataRow
For Each row In table.Rows
Console.WriteLine("{0}\{1}", _
row("ServerName"), row("InstanceName"))
Next
End If
End Sub
End Module