Connection string loaded from config file
-
I have:
configMap =
new ExeConfigurationFileMap { ExeConfigFilename = "ToolHistoryServer.exe.config" };
myCfg =
ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
dataSource = myCfg.AppSettings.Settings["DataSource"].Value;
cnStr = "Data Source='" + dataSource + "';" +
"Trusted_Connection=true;" +
"Database=ToolHistory";Config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="DataSource" value="NIGEL-PC\\SQLEXPRESS" />
</appSettings>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="50050" />
</channels>
</application>
</system.runtime.remoting>
</configuration>I have tried cnStr with and without the single quotes, but neither work. Something is wrong with my syntax. It compiles and runs, but data access fails. Can't debug because it is on the server side.
-
I have:
configMap =
new ExeConfigurationFileMap { ExeConfigFilename = "ToolHistoryServer.exe.config" };
myCfg =
ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
dataSource = myCfg.AppSettings.Settings["DataSource"].Value;
cnStr = "Data Source='" + dataSource + "';" +
"Trusted_Connection=true;" +
"Database=ToolHistory";Config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="DataSource" value="NIGEL-PC\\SQLEXPRESS" />
</appSettings>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="50050" />
</channels>
</application>
</system.runtime.remoting>
</configuration>I have tried cnStr with and without the single quotes, but neither work. Something is wrong with my syntax. It compiles and runs, but data access fails. Can't debug because it is on the server side.
-
Doesn't that give a connectionstring like below?
Data Source='NIGEL-PC\SQLEXPRESS';
Trusted_Connection = true;
Database = ToolHistory;What happens when you remove the quotes around the name of the datasource?
I are Troll :suss:
I would have thought so. I have just written test code to return cnStr, and I find that dataSource is NIGELPC\\\\SQLEXPRESS! Wrote a snippet to remove the extra \\ and now it works.