简体   繁体   English

ODBC连接字符串(DSN)

[英]ODBC connection string (DSN)

I'm developing a plugin for Excel (for customizable reporting and data extraction from various sources). 我正在开发Excel插件(用于来自各种来源的可自定义报告和数据提取)。

Right now I'm struggling with ODBC connection (DSN in particular). 现在,我正在努力进行ODBC connection (尤其是DSN)。 Even though I have created a dedicated DSN and pointed the app to use it, I had to specify the same information in the connection string (pwd, user name, db name etc.) to make it work. 即使我已经创建了专用的DSN并指出了要使用的应用程序,我也必须在连接字符串中指定相同的信息(pwd,用户名,数据库名称等)才能使其正常工作。

I don't want to expose this type of information in the xml file and wonder if it possible to force the app to use the info from DSN only (or, as alternative, to encode the conn. string in the customized xml file)? 我不想在xml文件中公开这种类型的信息,并且想知道是否有可能强制应用程序仅使用DSN中的信息(或者作为替代,在自定义xml文件中编码conn。字符串)?

You may want to encrypt connection string. 您可能需要加密连接字符串。 Details here 详情在这里

static void ToggleConfigEncryption(string exeConfigName)
{
    // Takes the executable file name without the
    // .config extension.
    try
    {
        // Open the configuration file and retrieve 
        // the connectionStrings section.
        Configuration config = ConfigurationManager.
            OpenExeConfiguration(exeConfigName);

        ConnectionStringsSection section =
            config.GetSection("connectionStrings")
            as ConnectionStringsSection;

        if (section.SectionInformation.IsProtected)
        {
            // Remove encryption.
            section.SectionInformation.UnprotectSection();
        }
        else
        {
            // Encrypt the section.
            section.SectionInformation.ProtectSection(
                "DataProtectionConfigurationProvider");
        }
        // Save the current configuration.
        config.Save();

        Console.WriteLine("Protected={0}",
            section.SectionInformation.IsProtected);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM