Making setup file with sql db file to work on another computer

Amer Shokry 1 Reputation point
2020-12-31T20:25:19.717+00:00

hi dears

Happy new year. I create a windows application connect to sql server 2016 database. I need to make a setup file with this database file to work another computers individually. these computers don't have sql server installed on it.

best regards;

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,889 questions
Visual Studio Setup
Visual Studio Setup
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Setup: The procedures involved in preparing a software program or application to operate within a computer or mobile device.
1,041 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 30,561 Reputation points Microsoft Vendor
    2021-01-01T06:47:41.947+00:00

    Hi @Amer Shokry ,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    For setup file in Visual Studio, you need to download and install Microsoft Visual Studio Installer Projects extension from Visual Studio Marketplace or from Extensions > Manage Extensions > Online > search and install Microsoft Visual Studio Installer Projects extension. After installing this extension, launch Visual Studio and you can add a new Setup Project in your solution.

    For configuring Setup Project, you need to Add Project Output, File... > choose project > select Primary output, Content Files… > OK. If you’d like to install the SQL Server in those computers by using Setup Project, the most important step is to select the SQL Server 2016 related options in Prerequisites from right-clicking Setup Project > Properties > Configuration Properties > Build > Prerequisites. Also, choose some necessary prerequisites to install and specify the install location for prerequisites.

    52647-test1.png

    52674-test2.png

    Best Regards,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments

  2. Bonnie DeWitt 811 Reputation points
    2021-01-03T01:12:50.203+00:00

    Hi @Amer Shokry ,

    The use of the phrase "setup file" might be misleading or ambiguous, but I think what you're looking for is a config file. If you add an app.config file to your Windows application project, you can specify a ConnectionString to your database there. When the application is compiled, a new config file will be created (or updated). It is a copy of your app.config and it will named after your .EXE file. So, if your application is MyApplication.exe then the config would be called MyApplication.exe.config

    When you distribute your app to another computer, all you have to do is change the ConnectionString in the MyApplication.exe.config file to point to a different database. If they are all connecting to the same database, then you don't have to change anything. The only thing necessary is that all the computers have network access to the SQL Server computer.

    The ConnectionString setting in the config looks like this:

    <?xml version="1.0" encoding="utf-8"?>  
    <configuration>  
      <appSettings>  
        <!-- you could use this for other settings. They are key/value pair settings, for example: -->  
        <add key="MyFirstAppSetting" value="Whatever it might be"/>  
      </appSettings>  
      <!-- But, this is what you need for your database -->  
      <connectionStrings>  
        <add name="MyConnectionString" connectionString="server=MyServerName;uid=MyUser;pwd=MyPassword;database=MyDatabase"/>  
      </connectionStrings>  
    </configuration>  
    

    In your application, get the ConnectionString from the config file like this:

    ConnectionStringSettingsCollection ConnectionStrings = ConfigurationManager.ConnectionStrings;  
    string myConnString = null;  
    // Always program defensively when processing data that could be modified by a user, in case they screw it up  
    if (ConnectionStrings != null && ConnectionStrings["MyConnectionString"] != null)  
        myConnString = ConnectionStrings["MyConnectionString"].ConnectionString;  
    

    The ConfigurationManager requires adding a reference to System.Configuration, which a lot of people miss. Here is a screenshot that shows step-by-step how to add the reference.

    52750-addsystemconfigurationscreenshot.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.