how to create Setup file of C#? RRS feed

  • General discussion

  • i want to know how to make a setup file that can run on any other computer?

    i am facing some problems when i build my code that i have sql connection string in my code and every pc has its own connection string. Is there any solution that i can make a sql base software but it can run on any computer? 

    Tuesday, August 14, 2018 8:53 AM

All replies

  • Hi,

    There are different options to overcome this issue.

    1. If you have control over the installed SQL instance on the different PCs, then try to use the default instance and  then the "Data Source" would be ".". Eg. "Data Source = ."

    2. Revise your application to load the first time running configuration windows form where the user needs to specify the connection string parameters in some textboxes.

    3. If you don't want to spend time in building the configuration Windows form as in option #2, then put the connection string in the app.config file, and add extra post installation step in your setup KB/guide to alter the connection string on the config file before running the application.

    Let me know if any of those worked with you.

    Good luck!

    Tuesday, August 14, 2018 9:15 AM
  • Another option to try is presenting a list of servers (if there is more than one), let the user select. If one than setup your connection string with the single server found.

    The following uses SMO via NuGet here. In the following example the method is in a class SmoOperations.

    public async Task<List<string>> GetServersAsync()
        var serverNames = new List<string>();
        await Task.Run(() =>
            serverNames = SmoApplication.EnumAvailableSqlServers(true)
                            .Select((row) => row.Field<string>("Name"))
        return serverNames;

    Example usage

    var ops = new SmoOperations();
    var servers = await ops.GetServersAsync().ConfigureAwait(true);
    if (servers.Count == 1)
        // use it
        // present list to user

    In the event SQL-Server is not available the code should be wrapped in a try-catch.

    Another option is to use Microsoft Connection dialog as shown here.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, August 14, 2018 10:38 AM