none
entity framework 5 on a windows service needs configuration strings RRS feed

  • Question

  • i have a windows service that uses entity framework 5 with .net framework 4

    EF5 needs a configuration string and since it runs as a service the configuration file should exist to the c:\windows\system32 folder

    Is it possible to work without the existance of the configuration file?

    Friday, November 9, 2012 10:04 AM

Answers

All replies

  • You could hardcode the connection string for entity framework but that is not advisable.

    It should work all just fine, you can place the service in any directory (it does not need to be c:\windows\system 32) we use program files\application name.

    Just add the app.config file to you solution and the config file [your service name].exe.config will be created automatically when building in your bin folder

    Copy your entire bin directory to your folder on the target machine e.g. program files\application name

    Open a command prompt as administrator navigate to your program files\application name folder and run installutil [your service name].exe

    hope this helps.

    Friday, November 9, 2012 3:16 PM
  • i want to set the connection string from the application code.

    I know how to set the sql connection string

    dBContext.Database.Connection.ConnectionString = SqlConnectionString();

    where sqlconnectionstring is a function that i create the required sql connection string.

    but if at the application config file the following lines are missing

        <add name="Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=AdventureWorks;user id=sa;password=sa;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

    then the application gives an error

    I want to set from the application code the entire entityconnection string without the need of the above line in the config file.

    Is that possible??

    Sunday, November 11, 2012 7:30 PM
  • Hi Iglezos,

    Welcome to the MSDN forum.

    Please check if this article is what you want: http://blogs.msdn.com/b/rickandy/archive/2008/12/09/explicit-connection-string-for-ef.aspx

    By this way, you can use the connection string directly instead of app.config file.

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by iglezos Monday, November 12, 2012 4:04 PM
    Monday, November 12, 2012 6:42 AM
  • thank you, for the link.

    I created a new constructor to my entity model that takes a parameter for the entityconnectionstring and used the above link to create dynamic the string and worked fine.

    Monday, November 12, 2012 4:03 PM