如何使用SQL Server数据库部署或发布Windows应用程序 [英] How to deploy or publish Windows app with SQL Server database

查看:270
本文介绍了如何使用SQL Server数据库部署或发布Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个带有SQL Server数据库的C#应用​​程序。当我尝试发布应用程序以测试它>>它在我的机器上正常工作(包括SQL Server数据文件夹中的数据库)>>但是当我将该发布的应用程序移动到另一台机器不工作。

I have developed a C# application with a SQL Server database. When I try to publish the application to test it >> it works correctly on my machine (that include the database in SQL Server data folder) >> but when I move that published app to another machine it doesn't work.

我想知道使用数据库一起部署项目的最简单方法

I want to know the simplest way to deploy the project with its database together

我在使用这个连接字符串 app.config

I am using this connection string in my app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="cs" 
         providerName="System.Data.ProviderName" 
         connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\KBank.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" />
  </connectionStrings>
</configuration>

我应该做什么,为了放置数据库与部署的应用程序和动态修改连接字符串数据库在 app.config

What should I do in order to place the database with the deployed app and dynamically modify the connection string for the database in app.config?

当我打开用户计算机上的项目时显示的异常说: / p>

the exception shown when i open the project on the users machines says:


用于为文件C附加自动命名数据库的Attempet:\Program
Files(x86)\ Microsoft SQL Server \MSSQL.1\MSSQL\Data\KBank.mdf失败,
a同名的数据库存在或指定的文件不能
打开,或其在UNC共享上的位置

An Attempet to Attach an auto-named database for file C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\KBank.mdf Failed, a database with the same name exists or specified file cannot be opened, or its location on UNC share

似乎无法读取SQL DataBase

it seems it is unable to read the SQL DataBase

推荐答案

我已经解决我的问题>问题是,我没有添加一个本地数据库到我的项目解决方案..所以当我尝试在另一台机器上的项目应用程序找不到指定的连接sting有路径:

I have resolved my problem > the problem was that i didn't add a Local Database to my project solution.. so when i try the project on another machine the application couldn't find the specified connection sting that have the path:


C:\Program文件(x86)\ Microsoft SQL
Server\MSSQL.1\ MSSQL \\ \\Data\KBank.mdf; Integrated Security = True; Connect
Timeout = 30; User Instance = True

C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\KBank.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True

当我添加本地数据库到我的项目解决方案连接字符串路径变为:

but when i added the local db to my project solution the connection string path became :


| DataDirectory | \KBank.mdf

|DataDirectory|\KBank.mdf

已成功附加项目文件
谢谢

it has been attached with the project files successfully thank you

这篇关于如何使用SQL Server数据库部署或发布Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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