问题描述
我已经创建了一个应用程序,还正确设置了它.
现在,我想添加自定义表单,以便在安装时可以提及数据源名称的详细信息.
为此,我从此链接
获得帮助因此,在安装程序类中,我已经编写了此
I''ve made an application, also made its setup properly.
Now i want to add custom form so that i can mention datasource name details at the time of installation.
For this i''m taking help from this link
So in the installer class i''ve written this
public override void Install(System.Collections.IDictionary stateSaver)
{
try
{
string dataSource = "Data Source =" + Context.Parameters["DataSource"];
string initialcatalog = "Initial Catalog=" + Context.Parameters["InitialCatalog"];
dataSource = dataSource + ";" + initialcatalog;
dataSource = dataSource + ";Integrated Security=SSPI;";
MessageBox.Show("instance=" + dataSource);
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
MessageBox.Show(Assembly.GetExecutingAssembly().Location + ".config");
//Getting the path location
string configFile = string.Concat(Assembly.GetExecutingAssembly().Location, ".config");
map.ExeConfigFilename = configFile;
System.Configuration.Configuration config = System.Configuration.ConfigurationManager.
OpenMappedExeConfiguration(map, System.Configuration.ConfigurationUserLevel.None);
string connectionsection = config.ConnectionStrings.ConnectionStrings
["SqlConnectionString"].ConnectionString;
ConnectionStringSettings connectionstring = null;
if (connectionsection != null)
{
config.ConnectionStrings.ConnectionStrings.Remove("SqlConnectionString");
MessageBox.Show("removing existing Connection String");
}
connectionstring = new ConnectionStringSettings("SqlConnectionString", dataSource);
config.ConnectionStrings.ConnectionStrings.Add(connectionstring);
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("connectionStrings");
}
catch (Exception ex)
{
throw new InstallException("A forced exception", ex);
}
}
在安装时,我收到两个错误消息
< img src ="http://i43.tinypic.com/2cr3u5c.jpg" border ="0" alt = 由TinyPic托管图像和视频">
< img src ="http://i43.tinypic.com/2ym9jk1.jpg" border ="0" alt = 由TinyPic托管图像和视频">
谁能指导我解决这个问题.
在此先谢谢您.
While installing i am getting two error message
<img src="http://i43.tinypic.com/2cr3u5c.jpg" border="0" alt="Image and video hosting by TinyPic">
<img src="http://i43.tinypic.com/2ym9jk1.jpg" border="0" alt="Image and video hosting by TinyPic">
Can anyone please guide me to solve this.
Thanks in advance.
推荐答案
这篇关于在安装Windows应用程序时添加数据源名称时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!