0

私のマシンにも同様にDSNのリストがあります

    private IEnumerable<string> EnumDsn(Microsoft.Win32.RegistryKey rootKey)
{
    Microsoft.Win32.RegistryKey regKey =  rootKey.OpenSubKey(@"Software\ODBC\ODBC.INI\ODBC Data Sources");
    if (regKey != null)
    {
        foreach (string name in regKey.GetValueNames())
        {
            string value = regKey.GetValue(name, "").ToString();
            yield return name;
        }
    }
}

私の意図は、各 DSN のドライバーの種類と、その取得方法を取得することです。

4

1 に答える 1

0

odbccp32.dll からSQLGetPrivateProfileString 関数を呼び出して、探している情報を取得できます。

lpszSection の引数として使用"ODBC Data Sources"し、データ ソース名 (DSN) を lpszEntry の引数として使用します。バッファーに返される値は、ドライバー名になります。

DLL と関数のインポートは、C# では次のようになります。

    [DllImport("odbccp32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    private static extern int SQLGetPrivateProfileStringW(string lpszSection, string lpszEntry, string lpszDefault, char[] RetBuffer, int cbRetBuffer, string lpszFilename);

VB.NET では次のようになります。

    <DllImport("odbccp32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
    Private Shared Function SQLGetPrivateProfileStringW(lpszSection As String, lpszEntry As String, RetBuffer As Char(), cbRetBuffer As Integer, lpszFilename As String) As Integer
于 2014-01-15T16:55:10.693 に答える