none
set connection string in linq dbml file for an app.config file RRS feed

  • Question

  • In a C# 2010  console application I am having the same problem that is listed in the following url:
    http://ddkonline.blogspot.com/2008/02/set-connection-string-in-linq-dbml-file.html.

    However I am having the problem wih an app.config file.

    My question is in the article, that refers to the "InvestmentManagementConnectionString", how should  I setup the correlation between  this connection to the app.config file?

    Can you show me me how the app.config file would be setup to reference the "InvestmentManagementConnectionString"?

    Thursday, November 8, 2012 6:57 AM

Answers

  • I have a console application and I have an app.config file in it, which looks like this:

    <?xml version="1.0"?>
    <configuration>
      <configSections>
      </configSections>
      <appSettings>
        <add key="RootFolder" value="D:\MyRootFolder" />
      </appSettings>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
      </startup>
    </configuration>
    

    As you can see I have my root folder address as RootFolder stored in <appSettings> section (as an example).

    Here is the usage:

     class Program
        {
            static void Main(string[] args)
            {
                var RootFolderName = System.Configuration.ConfigurationManager.AppSettings["RootFolder"];
                Console.WriteLine(RootFolderName);
            }
    }



    Please mark as reply if helped.
    Also visit my blog http://msguy.net/

    • Marked as answer by jazz_dog Sunday, November 11, 2012 3:17 AM
    Thursday, November 8, 2012 3:15 PM

All replies

  • Add reference of System.Configuration to your console application project and after that deal with:

    System.Configuration.ConfigurationManager.AppSettings["Key"]
    Or System.Configuration.ConfigurationManager.ConnectionStrings["Key"]
    objects



    Please mark as reply if helped.
    Also visit my blog http://msguy.net/

    Thursday, November 8, 2012 9:05 AM
  • By the way, take a look to one of mine articles, I think this will completely solve your problem.

    http://msguy.net/post/2012/11/08/LINQ-To-SQL-Connection-string-problem-solving.aspx


    Please mark as reply if helped.
    Also visit my blog http://msguy.net/



    Thursday, November 8, 2012 10:06 AM
  • Can you show me more code on how I would deal with System.Configuration.ConfigurationManager.AppSettings["Key"]

    Thursday, November 8, 2012 3:01 PM
  • I have a console application and I have an app.config file in it, which looks like this:

    <?xml version="1.0"?>
    <configuration>
      <configSections>
      </configSections>
      <appSettings>
        <add key="RootFolder" value="D:\MyRootFolder" />
      </appSettings>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
      </startup>
    </configuration>
    

    As you can see I have my root folder address as RootFolder stored in <appSettings> section (as an example).

    Here is the usage:

     class Program
        {
            static void Main(string[] args)
            {
                var RootFolderName = System.Configuration.ConfigurationManager.AppSettings["RootFolder"];
                Console.WriteLine(RootFolderName);
            }
    }



    Please mark as reply if helped.
    Also visit my blog http://msguy.net/

    • Marked as answer by jazz_dog Sunday, November 11, 2012 3:17 AM
    Thursday, November 8, 2012 3:15 PM