0

I have EF connection string in my web.config as shown below

  <connectionStrings>    
    <add name="Entities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=Source;Initial Catalog=Pricing;Integrated Security=False;UID=User;Pwd=password;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>   
  </connectionStrings>

and in my code I am doing this to get just the connection string which I am using for some other controls

SqlDataSource1.ConnectionString = ((System.Data.Entity.Core.EntityClient.EntityConnection)Entities.Current.Connection).StoreConnection.ConnectionString;

The issue I am facing is that I am getting the connection string but for some reason it does not have the password in it

Data Source=Source;Initial Catalog=Pricing;Integrated Security=False;UID=User;MultipleActiveResultSets=True

and so my connections are failing. Can someone please tell me what I am doing wrong here. I just need the below part

Data Source=Source;Initial Catalog=Pricing;Integrated Security=False;UID=User;Pwd=password;MultipleActiveResultSets=True

Thanks

Edit : So looks like that the password is hidden by design https://social.msdn.microsoft.com/Forums/en-US/5a5730be-c93e-4da5-a614-7ed629f06f51/why-would-password-of-connectionstring-be-filtered-after-instantiating-any-object-in-entity?forum=adodotnetentityframework

Not sure if there is any other way

SP1
  • 1,182
  • 3
  • 22
  • 47

1 Answers1

0

Looks like ConfigurationManager is available in Core (Is ConfigurationManager.AppSettings available in .NET Core 2.0?).

Why not try that? Then pull the connection string and password (stored as separate key under if need be) out of the web.config.

RTF
  • 421
  • 2
  • 8
  • Thanks for your reply..but that would give me the whole connection string I was just looking for the data source part ..."metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=Source;Initial Catalog=Pricing;Integrated Security=False;UID=User;Pwd=password;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" – SP1 Sep 11 '19 at 23:25