How to deploy C# windows application (setup file) with database and how to manage connection string on client machine

我只是一个虾纸丫 提交于 2019-12-12 04:32:01

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/40146336/how-to-deploy-c-sharp-windows-application-setup-file-with-database-and-how-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!