[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with Data Link Proerties Dialog

Posted on 2009-04-16
13
Medium Priority
?
198 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:jules182
  • 7
  • 6
13 Comments
 
LVL 12

Expert Comment

by:wht1986
ID: 24157248
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
 
LVL 12

Expert Comment

by:wht1986
ID: 24157289
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
 
LVL 12

Expert Comment

by:wht1986
ID: 24157327
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jules182
ID: 24157454
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
 

Author Comment

by:jules182
ID: 24157489
Not the list of servers (see attached file)
DataLink.jpg
0
 
LVL 12

Expert Comment

by:wht1986
ID: 24158326
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
 

Author Comment

by:jules182
ID: 24159277
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
 
LVL 12

Expert Comment

by:wht1986
ID: 24159427
Oh, you just want to display the built in dialog box?

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

Author Comment

by:jules182
ID: 24169000
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
 
LVL 12

Expert Comment

by:wht1986
ID: 24169538
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
 

Author Comment

by:jules182
ID: 24174879
Hi wht1986,

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

Thanks once again for all your help.

Cheers,

Jules
0
 
LVL 12

Accepted Solution

by:
wht1986 earned 2000 total points
ID: 24176596
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
 

Author Closing Comment

by:jules182
ID: 31570906
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

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 20 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question