How to deploy C# windows application (setup file)

2019-09-18 02:40发布

I am creating C# Windows Application in Visual Studio 2015.

Question:

How to deploy C# Windows Application (setup file) with SQL Server database with database connection string.

I create common connection string in app.config :

<connectionStrings>
      <add name="conString" 
           providerName="System.Data.sqlclient"          
           connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=
                 'C:\Users\DEVELOPERS\Documents\Visual Studio 2015\Projects\Provision1\
                  Provision1\provision1.mdf';Integrated Security=True"/>

</connectionStrings>

Now connection string path location shows my machine.

Then after installation .exe how to connect database and how to manage connection string on client machine.

enter image description here

1条回答
forever°为你锁心
2楼-- · 2019-09-18 03:30

The easiest way you can do is:

  1. Save your connection string in app.config is absolutly common
  2. Compile your Project with Release settings
  3. Take your .exe file from /bin/release/.. Folder
  4. The Database should be connected via the connection string. If the database is not connected via network you need to deploy it as well.
  5. Make sure your clients have .Net Framework installed

If you definitive need a setup.exe which installs your software, you can make a new project which is of type setup-programm. Watch this link for description.

If you don't want your users to see the connectionstring you can use a ConnectionStringBuilder. Save just a part of your connection string to app.config and build the rest via Quellcode. Watch this MSDN-Article.

查看更多
登录 后发表回答