如何使用数据库部署C#Windows应用程序(安装文件)以及如何在客户端计算机上管理连接字符串 [英] How to deploy C# windows application (setup file) with database and how to manage connection string on client machine

查看:48
本文介绍了如何使用数据库部署C#Windows应用程序(安装文件)以及如何在客户端计算机上管理连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Visual Studio 2015 中创建C# Windows应用程序.

问题:

如何使用带有数据库连接字符串的SQL Server数据库部署C#Windows应用程序(安装文件).

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

我在 app.config 中创建公用连接字符串:

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.

然后在安装 .exe 之后如何连接数据库以及如何在客户端计算机上管理连接字符串.

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

推荐答案

最简单的方法是:

  1. 将连接字符串保存在app.config中是很常见的
  2. 使用发布设置编译项目
  3. 从/bin/release/..文件夹中获取.exe文件
  4. 数据库应通过连接字符串连接.如果数据库未通过网络连接,则也需要对其进行部署.
  5. 确保您的客户端已安装.Net Framework

如果您最终需要安装软件的setup.exe,则可以创建一个类型为setup-programm的新项目.观看此链接以了解说明.

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.

如果您不希望用户看到连接字符串,则可以使用ConnectionStringBuilder.将连接字符串的一部分保存到app.config中,然后通过Quellcode构建其余部分.观看此 MSDN-文章.

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.

这篇关于如何使用数据库部署C#Windows应用程序(安装文件)以及如何在客户端计算机上管理连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆