none
Can MS confirm: It's not possible to pass in connection string to EF in DB-first RRS feed

Answers

  • Hello albra,

    >>Is this really not possible?

    I am not sure what Entity Framework version the OP in your provided link used, I used EF6 and did what the OP described: remove the connection string of the app.config and put it as parameter on the DbContext constructor, however, it works. Please note that the connection string needs to be modified when using in runtime, here is the demo code:

    public DFDBEntities()
    
                : base(GetConnectionString())
    
            {
    
            }
    
    
    
            private static string GetConnectionString()
    
            {
    
                return @"metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=(localdb)\Projects;initial catalog=DFDB;integrated security=True;multipleactiveresultsets=False;connect timeout=30;App=EntityFramework'";
    
            }
    


    Replace “"” with “’”.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by albra Wednesday, July 1, 2015 8:30 AM
    Wednesday, July 1, 2015 6:42 AM
    Moderator

All replies

  • Hello albra,

    >>Is this really not possible?

    I am not sure what Entity Framework version the OP in your provided link used, I used EF6 and did what the OP described: remove the connection string of the app.config and put it as parameter on the DbContext constructor, however, it works. Please note that the connection string needs to be modified when using in runtime, here is the demo code:

    public DFDBEntities()
    
                : base(GetConnectionString())
    
            {
    
            }
    
    
    
            private static string GetConnectionString()
    
            {
    
                return @"metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='data source=(localdb)\Projects;initial catalog=DFDB;integrated security=True;multipleactiveresultsets=False;connect timeout=30;App=EntityFramework'";
    
            }
    


    Replace “"” with “’”.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by albra Wednesday, July 1, 2015 8:30 AM
    Wednesday, July 1, 2015 6:42 AM
    Moderator
  • Thank you, I had subtle differences but using your method on EF6 works.
    Wednesday, July 1, 2015 8:32 AM