%APPDATA% in connection string is not substituted for the actual folder?

后端 未结 3 1050
别那么骄傲
别那么骄傲 2020-12-06 06:29

When using WPF and entity-framework I have an APP.CONFIG that looks like the following:




        
3条回答
  •  攒了一身酷
    2020-12-06 06:59

    You have to replace the %APPDATA% in the code with the relative path -

    var connectionString = ConfigurationManager.ConnectionStrings["DatabaseEntities"]
                                                               .ConnectionString;    
    connectionString.Replace("%APPDATA%", 
      Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
    

提交回复
热议问题