2017-03-17 230 views
0

我正在開發一個Excel插件(用於從各種來源定製報告和數據提取)。ODBC連接字符串(DSN)

現在,我與ODBC connection(DSN尤其是)掙扎。儘管我創建了一個專用DSN並指出應用程序使用它,但我必須在連接字符串(pwd,用戶名,db名稱等)中指定相同的信息才能使其正常工作。

我不想在xml文件中公開此類信息,並想知道是否可以強制應用程序僅使用DSN中的信息(或者,作爲替代方案,可以在定製中對連接字符串進行編碼xml文件)?

+0

請顯示您所做的研究,並解釋爲什麼它沒有幫助。這是一個非常常見和廣泛記錄的話題。不顯示你的研究吸引反對票,尤其是對可能有重複答案的常見問題。 –

+0

沒有什麼特別的。我有一個文件(包含連接信息的自定義XML文件),像這樣的: 天青 ODBC; DSN = Azure_SQL; UID =名爲myUsername; PWD = userPwd;數據庫= TESTDB; 我不明白爲什麼我需要重複我已經進入DSN相同的數據。我期望以下的東西工作: ODBC; Dsn = Azure_SQL; 即指向應用程序。僅限於DSN,但它不起作用。我不會說這個問題很常見。 –

+0

從我在這裏看到的(https://www.connectionstrings.com/dsn/)它無論如何都需要用戶名和密碼,但我不想將它們保存在共享的xml文件中。現在看來,該文件/康涅狄格州。字符串加密只是選項。 –

回答

0

您可能想要加密連接字符串。詳細信息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); 
    } 
} 
+0

謝謝陪審團,這也是我正在考慮的事情。如果我不想與DSN一起計算,這是我的備用選項。 –

+0

@JohnBull,實際上如MS建議的那樣,在安全性方面,配置加密優於DSN:https://msdn.microsoft.com/en-us/library/ee658127.aspx –

相關問題