Software Development Network>> Visual C#>> Getting Names of System Data Sources in Windows
using
public
{
DbProviderFactory
DataTable
connection.ConnectionString =
tables = connection.GetSchema(
System.
}
Shakeel,
Can you kindly mark the post as an answer
If you are looking for the list of System DSN's then they are stored in
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources
Here is the code for accessing them-
static
[
GetODBCS(key);
Now,examine DBQ to get the name of the database
Hope this helps
Getting Names of System Data Sources in Windows
norsd
adam kromm
using
System.Data.Common;using
System.Data;public
class GetName{
public
static void Main(){
DbProviderFactory
factory = DbProviderFactories.GetFactory("System.Data.OleDb");DataTable
tables = null;using
(DbConnection connection = factory.CreateConnection()){
connection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;"; string[] restrictions = null; connection.Open();tables = connection.GetSchema(
"Tables", restrictions); foreach (DataRow row in tables.Rows){
for (int i = 0; i < tables.Columns.Count; ++i)System.
Console.WriteLine(rowSystem.
Console.WriteLine();}
}
}
}
BatesManty
Cheers to you man! :D
Would you also know how to get a list of all the table names from an MS Access database using C#
Thanks again.
Shakeel
:)
Lenitcha
Shakeel,
Can you kindly mark the post as an answer
chris_dk
If you are looking for the list of System DSN's then they are stored in
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources
Here is the code for accessing them-
static
class Program{
/// <summary> /// The main entry point for the application. /// </summary>[
STAThread] static void Main(){
RegistryKey localMachineKey = Registry.LocalMachine; RegistryKey key = localMachineKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources");GetODBCS(key);
private static void GetODBCS(RegistryKey key){
string[] odbcs = key.GetValueNames();//Gives you all the names of system DSN's foreach(string valuename in key.GetValueNames()){
MessageBox.Show(valuename + " " + key.GetValue(valuename).ToString());Now,examine DBQ to get the name of the database
}
}
}
Hope this helps
dafan
Shakeel