In a C# 2008 desktop/console application, I created the connections to the database using linq to sql. Everything worked fine until I moved the
code to point to a different database. Somehow the original database connections are being saved and the values from the app.config file
are not being used.
I tried to do what the following link: http://refat38.wordpress.com/2012/01/30/unpick-linq-to-sql-connection-string-from-application-settings/,
said to do however, I do not know what the following statement means to do from this link:
Now Right Click and open the Properties on your DAL or project containing your LINQ to SQL classes and remove the connection string "Application Setting" reference on the Settings tab.
I also tried to add the following to the *.designer.cs file:
base(ConfigurationManager.ConnectionStrings["esample.Properties.Settings.devtestConnectionString"].ConnectionString, mappingSource) and attached
a system.configuration file as a reference.
1. The following code is from the app.config file:
providerName="System.Data.SqlClient" />
2. The following is from the settings.settings file
The following is from the settings.designer.cs file
namespace esample.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=dev;Initial Catalog=devtest;Integrated Security=True")]
public string devtestConnectionString {
get {
return ((string)(this["devtestConnectionString"]));
}
}
}
}
The following is from the *.designer.cs
namespace esample
{
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;
using System.Configuration;
[System.Data.Linq.Mapping.DatabaseAttribute(Name="devtest")]
public partial class esampleDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
public esampleDataContext() :
base(global::esample.Properties.Settings.Default.devtestConnectionString, mappingSource)
//base(ConfigurationManager.ConnectionStrings["esample.Properties.Settings.devtestConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public esampleDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
Can you show me code and/or tell me how to solve this problem so I can obtain the value from the app.config file?
scampercatPosted Nov 17, 2012, 4:31 PM
providerName="System.Data.SqlClient" />
is different than my answer:
providerName="System.Data.SqlClient" />
I am using
Vithal WadjePosted Nov 16, 2012, 10:44 PM
providerName="System.Data.SqlClient" />