This is a migrated thread and some comments may be shown as answers.

Getting Connection String from app.config

1 Answer 131 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Steve
Top achievements
Rank 1
Steve asked on 04 Feb 2010, 03:26 PM
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. 

SqlConnection

 

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

 


-Steve-

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 08 Feb 2010, 04:23 PM
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.

Greetings,
Petar
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.
Tags
Databases and Data Types
Asked by
Steve
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or