Problem with Data Link Proerties Dialog

Hi,

I'm implementing a Data Link Properties dialog in an app of mine.

The problem is, I'm probably getting a third of the (OLEDB) sources that are shown in the  Data Link dialog from VS2008 and other applications  (mainly Sql Server - no Access, Oracle etc.)

Has any body got any ideas what's wrong (I've been looking on the web for two days solid now) or any pointers to a solution.

Cheers,

Jules

Dim instance As DataLinksClass = New DataLinksClass
    Dim connection As New ConnectionClass
 
    If (instance.PromptNew = True) Then
 
      appSettings.ConnectionString = connection.ConnectionString
      appSettings.DataProvider = connection.Provider
 
      Dim startPos As Integer = connection.ConnectionString.IndexOf("Catalog=") + 8
      Dim endPos As Integer = InStr(startPos, connection.ConnectionString, ";") - 1
      Dim dbNameLength = endPos - startPos
      appSettings.DatabaseName = connection.ConnectionString.Substring( _
                                             startPos, dbNameLength)
      LoadScreen()
    End If
 
    connection = Nothing
    instance = Nothing

Open in new window

jules182Asked:
Who is Participating?
 
wht1986Connect With a Mentor Commented:
the link at http://www.dotnet247.com/247reference/msgs/5/26311.aspx had the follwoing code for searching the registry
Imports Microsoft.Win32
Imports System.Collections
 
Module Module1
 
Sub Main()
Dim ts As DateTime = Now
Dim i As Integer
Dim de() As DictionaryEntry = SearchOleDbProviders()
 
' Shows the duration of the process
Console.Write(Now.Subtract(ts).Ticks / TimeSpan.TicksPerMillisecond
& " milliseconds")
Console.WriteLine()
 
' Shows how many providers were found
Console.Write(de.Length & " OLE DB Providers")
Console.WriteLine()
Console.WriteLine()
 
' Displays the ProgID and name of each provider
For i = 0 To de.Length - 1
Console.Write(de(i).Key)
Console.Write(vbTab & " - " & vbTab & de(i).Value)
Console.WriteLine()
Next
 
'Waits for user input
Console.ReadLine()
End Sub
 
Function SearchOleDbProviders() As DictionaryEntry()
Dim Providers() As DictionaryEntry
Dim nProviders As Int16
 
nProviders = -1
ReDim Providers(0)
 
' I am only interested in the CLSID subtree
Dim keyCLSID As RegistryKey =
Registry.ClassesRoot.OpenSubKey("CLSID", False)
Dim keys() As String = keyCLSID.GetSubKeyNames()
Dim de As DictionaryEntry
Dim i As Int32
 
' Search through the tree just one level
For i = 0 To keys.Length - 1
Dim key = keyCLSID.OpenSubKey(keys(i), False)
 
' Search for OLE DB Providers
de = SearchKeys(key)
If Not (de.Key Is Nothing) Then
' Found one, add it to the Dictionary
nProviders = nProviders + 1
ReDim Preserve Providers(nProviders)
Providers(nProviders) = de
End If
Next
Return Providers
End Function
 
Function SearchKeys(ByVal key As RegistryKey) As DictionaryEntry
Dim i As Int32
Dim de As DictionaryEntry
 
'Tries to find the "OLE DB Provider" key
Dim key2 As RegistryKey = key.OpenSubKey("OLE DB Provider")
 
If Not (key2 Is Nothing) Then
' Found it, fills the DictionaryEntry
de = New DictionaryEntry()
Dim sValues() As String = key2.GetValueNames()
de.Key = key.OpenSubKey("ProgID", False).GetValue(sValues(0))
Dim sValues2() As String = key2.GetValueNames()
de.Value = key2.GetValue(sValues2(0))
End If
Return de
End Function
End Module

Open in new window

0
 
wht1986Commented:
i've used sql-dmo to get a list of servers in the past (its what the MS sql manager uses)

there's an example on code project
http://www.codeproject.com/KB/database/serverenum.aspx
0
 
wht1986Commented:
you can also use the SqlDataSourceEnumerator

using System.Data;
using System.Data.Sql;

SqlDataSourceEnumerator servers = SqlDataSourceEnumerator.Instance;
DataTable serversTable = servers.GetDataSource();

foreach(DataRow row in serversTable.Rows)
{
string serverName = string.format(\"{0}\\\\{1}\", row[0], row[1];
// Add this to your list
}
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
wht1986Commented:
sorry i had some syntax errors in that, here is the same that compiles

            SqlDataSourceEnumerator servers = SqlDataSourceEnumerator.Instance;
            DataTable serversTable = servers.GetDataSources();
            foreach(DataRow row in serversTable.Rows)
            {
                string serverName = string.Format("{0}\\\\{1}", row[0], row[1]);
            }
0
 
jules182Author Commented:
Hi wht1986,

Thanks for your answer, however it's not what I was looking for. I need to know why the OLEDB Data Link Properties is not showing all the data sources as VS2008 does on the same system.

Regards

Jules
0
 
jules182Author Commented:
Not the list of servers (see attached file)
DataLink.jpg
0
 
wht1986Commented:
Ohhhhh,  heres a couple of quick links

previous response to a similar question
http://www.experts-exchange.com/Database/Miscellaneous/Q_20617638.html

example using OLEDB Providers Enumeration
http://www.advancode.com/articles.php?page=oledbproviders

another example that parses the registry
http://www.dotnet247.com/247reference/msgs/5/26311.aspx
0
 
jules182Author Commented:
Wht1986,

Thanks for all your input. However, I'm just trying to get the Data Link Properties box working the same as the Datalinks class in other applications on my PC. I don't want to rely on *.Udl files and I don't want to redevelop this dialog.

Below is the full list (Data Links Dialog) from another app.

Could I be missing an import in my project references?

Regards,

Jules
Datalink2.jpg
0
 
wht1986Commented:
Oh, you just want to display the built in dialog box?

I think this link might help
http://support.microsoft.com/kb/286189
0
 
jules182Author Commented:
Hi,

Sorry to take so long to get back to you. Tried that as well but still only shows the subset of OLEDB providers as above.

Cheers

Jules
0
 
wht1986Commented:
Sorry that is all I know regarding showing the built in dialog.  If you want to build your own and scan through the registry keys, I can help you with doing that.
0
 
jules182Author Commented:
Hi wht1986,

That sounds good. If you wouldn't mind posting an example.

Thanks once again for all your help.

Cheers,

Jules
0
 
jules182Author Commented:
Thanks very much for your help. It sames the problem lies with XP Pro x64. You have to give different registry keys. Back to the drawing board....................
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.