How do I create an ODBC DSN entry using C#?

前端 未结 7 1243
旧巷少年郎
旧巷少年郎 2020-11-29 23:43

I\'m working on a legacy application that has a C++ extended stored procedure. This xsproc uses ODBC to connect to the database, which means it requires a DSN to be config

7条回答
  •  时光说笑
    2020-11-29 23:50

    +1 for Barnwell's code!

    However, I think his DSNExists() is querying the wrong key. I think it should be this:

    public static bool DSNExists(string dsnName) 
    { 
        var sourcesKey = Registry.LocalMachine.CreateSubKey(ODBC_INI_REG_PATH + "ODBC Data Sources"); 
        if (sourcesKey == null) throw new Exception("ODBC Registry key for sources does not exist"); 
    
        return sourcesKey.GetValue(dsnName) != null; 
    } 
    

提交回复
热议问题