2

I am creating a test project using IBM's Rational Functional Tester(RFT) tool(we are using the VB version of it and it only supports till .net 3.5).In this project I am making all database queries using the entity framework.The problem is entity framework retrieves "Metadata", "Connection String" etc from the App.Config file,and RFT won't let me add a App.Config to the project(I guess it is designed that way -- I googled adding an App.Config file to an rft project and came up with nothing), and the Entity Framework requires you to have the app.config file at the entry point.I was building the string to pass to entity framework in code, but my boss really does not like that. So looking at my options I think any of the below 2 solutions should suffice(or if you have a better solution please advise).

  1. Is their any way to load an App.Config during run-time.
  2. Is their any way to add an App.Config to an RFT project(should really be my first question).

If you guys could help me with this it will be great. Thanks in advance.

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
user602182
  • 139
  • 1
  • 9
  • In a project i am currently working on. I am connecting through an entity context, i have no reference to EF in my web.config. Are you absolutely sure you need an config ? – Keith Beard Jan 17 '12 at 02:19
  • @kcbeard : Weird i added a comment yesterday but don't seem to see it. To answer your comment Yes i do need a config file, i have created a vb.net console application just to test whether it was rft or something else, it turns out that after adding the config file to the console app it works without any issues. – user602182 Jan 18 '12 at 15:02
  • @kcbeard http://stackoverflow.com/questions/3491165/the-specified-named-connection-is-either-not-found-in-the-configuration-not-int – user602182 Jan 19 '12 at 01:28
  • Yeah i have nevered worked without a config file so i wouldnt really know if its was needed. I just know i defin my entity context or basically define my Database connections at run time so entity frameworks auto config edits always are removed when working on a project. Basically because connection strings happen on a per user basis. I wish i could help more but i dont have any experience with what you are doing specifically. – Keith Beard Jan 19 '12 at 04:03
  • @kcbeard: hey i found a way pasted the answer below, thanks for help – user602182 Jan 20 '12 at 21:18

1 Answers1

2

After a lot of research i found you can load the config file at runtime by using,

      ExeConfigurationFileMap map = new ExeConfigurationFileMap();
      map.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Assembly.GetExecutingAssembly().ManifestModule.Name + ".config");
      Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
      var configValue = config.ConnectionStrings.ConnectionStrings["refrenceNameinConfigfile"].ConnectionString;

just make sure your App.config is within the folder where your exe file is running

Keith Beard
  • 1,601
  • 4
  • 18
  • 36
user602182
  • 139
  • 1
  • 9