Getting Connection String from app.config

2 posts, 0 answers
  1. Steve
    Steve avatar
    11 posts
    Member since:
    Jan 2010

    Posted 04 Feb 2010 Link to this post

    I have created a C# project using the Telerik ORM and the app.config file was created with the necessary connection string. I would like to retrieve that connection string to use to create SqlConnection to the same database. However, ConfigurationManager.ConnectionString["DatabaseConnection"].ConnectionStrings does not return the connection string in the file. Is there a way to access the connection string contained in the app.config file and retrieve a string value to be assign to a SqlConnection. 



    conn = request.CreateConnection(ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString);


  2. PetarP
    PetarP avatar
    754 posts

    Posted 08 Feb 2010 Link to this post

    Hello Steve,

    Usually this is the method to retrieve a connection string. We have tested it with our application and the call to ConfigurationManager returns the expected result. The only possible reason that might be causing the method not to return the correct connection string is if the supplied name is not correct. Please note that the default name for Telerik OpenAccess ORMs connection is DatabaseConnection1. Maybe you omitted the extra 1 at the end in your application? Please double check your connection name and let us know if this works for you.

    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. DevCraft banner
Back to Top