By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,365 Members | 3,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,365 IT Pros & Developers. It's quick & easy.

data sources using C#

P: n/a
I want to get the list of data sources on the server machine using C# and
ASP.NET
any clues how to get that...I have done this using VB using SQLDataSources
function from ODBC32.dll

thanks
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ODBC DSN's? You can read the registry under HKLM\Software\ODBC\ODBC.INI...

"abcd" <ab**@abcd.com> wrote in message
news:e$**************@tk2msftngp13.phx.gbl...
I want to get the list of data sources on the server machine using C# and
ASP.NET
any clues how to get that...I have done this using VB using
SQLDataSources
function from ODBC32.dll

thanks

Nov 17 '05 #2

P: n/a
Hi,

I don;t know of any managed way of doing that , but you can p/invoke it.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"abcd" <ab**@abcd.com> wrote in message
news:e$**************@tk2msftngp13.phx.gbl...
I want to get the list of data sources on the server machine using C# and
ASP.NET
any clues how to get that...I have done this using VB using
SQLDataSources
function from ODBC32.dll

thanks

Nov 17 '05 #3

P: n/a
Here is the code that I use to get a SortedList of all the DSN names
from the registry...

<code>
/// <summary>
/// Reads the local user/system DSN registry entries and returns a
SortedList of Data Source Names.
/// </summary>
/// <remarks>In the event that a DSN exists in both the User and System
registries,
/// the User DSN takes precedence over the System DSN.</remarks>
/// <returns>The SortedList of Data Source Names</returns>
/// <seealso cref="System.Collections.SortedList"></seealso>
public static SortedList listAllDSN()
{
SortedList allDSN = new SortedList();

// Get User DNS Names
RegistryKey reg = (Registry.CurrentUser).OpenSubKey("Software");
reg = reg.OpenSubKey("ODBC");
reg = reg.OpenSubKey("ODBC.INI");
reg = reg.OpenSubKey("ODBC Data Sources");

if (reg != null)
{
// Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
foreach ( string s in reg.GetValueNames() )
{
allDSN.Add( s , null );
}
}
try
{
reg.Close();
}
catch ( System.Exception ex )
{
}

// Get System DNS Names
reg = (Registry.LocalMachine).OpenSubKey("Software");
reg = reg.OpenSubKey("ODBC");
reg = reg.OpenSubKey("ODBC.INI");
reg = reg.OpenSubKey("ODBC Data Sources");

if (reg != null)
{
// Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
foreach ( string s in reg.GetValueNames() )
{
try
{
allDSN.Add( s , null );
}
catch ( System.Exception ex )
{
}
}
}
try
{
reg.Close();
}
catch ( System.Exception ex )
{
}

return allDSN ;
}
</code>

Joel

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.