Automatically Detect Server Name of Machine in App.config

I am developing a Desktop Application in C#. An I want to use MSSQL Server Database in it through Entity Framework. I want to know that how can I make app-config file automatically detect server name in Connection String tag. As when I will deploy my application through a setup. It will install on another machine. It may have different server name. So I want my app-config to automatically detect the server name available on that machine. I knew there was a way but I have forgotten it. Please help me here. Thanks

1 answer

  • answered 2018-07-12 06:47 PepitoSh

    You don't necessarily have to. You can refer to a local database like this:


    The whole connection string:

        <add name="ActiveConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=NameOfTheDatabase;Integrated Security=True" providerName="System.Data.SqlClient"/>