如何部署Windows窗体数据库应用程序

编程入门 行业动态 更新时间:2024-10-22 23:46:13
本文介绍了如何部署Windows窗体数据库应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发需要与SQL Server通信的Windows窗体应用程序。一旦连接字符串尝试连接到无效的地址,我正在部署应用程序时遇到问题。

I am developing a windows forms application that needs to communicate with the SQL Server. I'm facing a problem when I deploy the application once the connection string is trying to connect to an invalid address.

我已经搜索了很多,我发现连接字符串必须具有 | DataDirectory | 指令。现在.mdf文件位于目录 C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA 。实际上连接字符串是: connectionString =Server = .\SQLExpress; AttachDbFilename = | DataDirectory | PDVDatabase.mdf; Database = PDVDATABASE; Trusted_Connection = Yes;

I've already searched a lot and I found out the connection string must have the |DataDirectory| directive. Now the .mdf file is located on the directory C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA. Actually the connection string is:connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|PDVDatabase.mdf;Database=PDVDATABASE;Trusted_Connection=Yes;"

我的应用程序连接到数据库的唯一方法是由Server Explorer(我使用的是Visual Studio 2013),其中我获取了我设置的.mdf文件的静态连接字符串在app.config中,但是在部署之后这种方式将不起作用。

The only way my app connects to the database is by the Server Explorer (I'm using Visual Studio 2013) where I get the static connection string of the .mdf file I set up in the app.config, but that way won't work after the deployment.

我的问题是:在部署之后如何连接我的应用程序,以便与.mdf文件通信? (我正在使用安装项目进行部署)。可能是错的?

My question is: How do I do to connect my app after the deployment in order to communicate with the .mdf file? (I'm using a setup project for deployment). What's can be wrong?

感谢。

推荐答案

很多事情需要解决

1) You need a copy of your MDF and LDF files to be distributed with your app 2) You need to know if your user has Sql Server installed in its internal LAN or its PC If the previous condition is true then 3.1) You need to attach your copy to the end user Sql Server Instance 3.2) You need to change your connection string to point to the end user Sql Server Instance else 4.1) You need to distribute and install LOCALDB 4.1) You need to prepare the connection string for LOCALDB

有些链接可以帮助您完成此任务

Some links to help you in this task

要附加和分离数据库信息 对于 LOCALDB 信息 LocalDb的Connectionstring 查找Sql服务器实例遍及您的网络

更多推荐

如何部署Windows窗体数据库应用程序

本文发布于:2023-11-03 20:21:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   应用程序   数据库   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!