提前致谢。如果你能给我发送任何有用的样本I am trying to connect to my sql server through WPF application. i defined a connectionstring in my MYOWN.COnfig file but i am not able to access it in my code.i have already added reference to System.Configuration in my refrence folder my config looks like"in configuration section i have defined my connectionstring as below-configuration- -configsections- -/configsections- -connectionstrings- -add name="con" connectionstring="Data Source=MyserverName;Initial<br mode=" hold=" /> Catalog=myDBName;Integrated Security=false;User Id=AdminUser;<br mode=" providername="System.Data.SqlClient" /- -/connectionstrings- /configuration-"please helpThanks in advance. if you can mail me any samples that will be a great help推荐答案建议使用app.config而不是这样的配置,除非确实存在这样的需求设计。 您需要通过 ExeConfigurationFileMap类 [ ^ ] 试试这个 -It is recommended to use app.config instead of such config unless there is truly exists demand for such design.You need to map the config file through ExeConfigurationFileMap Class[^]Try this-ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();fileMap.ExeConfigFilename = @"D:\YourFolder\myown.config";System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);string constring=config.AppSettings.Settings["con"].Value.ToString(); 希望,它有帮助:)Hope, it helps :) 这篇关于无法访问MYOwn.Config中定义的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-06 00:00
查看更多