问题
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:
- Save your connection string in app.config is absolutly common
- Compile your Project with Release settings
- Take your .exe file from /bin/release/.. Folder
- The Database should be connected via the connection string. If the database is not connected via network you need to deploy it as well.
- 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