简体   繁体   English

使用 SQL Server 数据库发布 C# 桌面应用程序

[英]Publish C# Desktop Application with SQL Server database

I have a Visual Studio project that has different Windows Forms and a SQL Server database attached.我有一个 Visual Studio 项目,它有不同的 Windows 窗体和一个附加的 SQL Server 数据库。 I want to install this project on my client computer (others).我想在我的客户端计算机(其他)上安装这个项目。 As I haven't published any project before, can someone guide me in an easy way.由于我之前没有发布过任何项目,有人可以以简单的方式指导我。

When I tried to publish (installed) this project in my computer (setup file would be created and the application would be installed but) but I get the error shown below while saving update delete data.当我尝试在我的计算机上发布(安装)这个项目(将创建安装文件并安装应用程序)但我在保存更新删除数据时收到如下所示的错误。 Please guide me correctly.请正确指导我。

在此处输入图片说明

You are taking a completely wrong approach here.您在这里采取了完全错误的方法。

Databases are not meant to be installed in client's computer.数据库并不打算安装在客户的计算机上。 If you have a client/server app, the database should be located only in your server, and the client will access it/request to write into it by sending requests over a protocol like TCP, which your server will react to.如果你有一个客户端/服务器应用程序,数据库应该只位于你的服务器中,客户端将通过像 TCP 这样的协议发送请求来访问它/请求写入它,你的服务器会对此做出反应。

When you add a database to an app, you provide a connection string and this connection string is related to YOUR instance of the database.当您将数据库添加到应用程序时,您需要提供一个连接字符串,该连接字符串与您的数据库实例相关。 If you wanted every client to use a unique DB, you'd need to go over to their computers, install a DBMS, create the database there, then edit the program code to include the connection string for the specific client instance.如果您希望每个客户端都使用唯一的 DB,则需要转到他们的计算机,安装 DBMS,在那里创建数据库,然后编辑程序代码以包含特定客户端实例的连接字符串。 Obviously this is not a viable option unless the clients you're talking about are just like your immediate family/roommates.显然,这不是一个可行的选择,除非您所谈论的客户就像您的直系亲属/室友。

If you intend to provide your clients app with saving/reading data functionality, you'd need to implement it by having the data written into a local file which the program will be able to read from, such as a csv or a tab delimited file.如果您打算为您的客户端应用程序提供保存/读取数据功能,您需要通过将数据写入本地文件来实现它,程序将能够读取该文件,例如 csv 或制表符分隔文件. Not through a database.不是通过数据库。 At least not SQL server.至少不是 SQL 服务器。 If you're completely obligated to use a DB, then think about an embedded, serverless DB like one from SQLite如果您完全有义务使用数据库,那么可以考虑使用 SQLite 中的嵌入式无服务器数据库

The reason you're getting that error is because the client's program is trying to look for the database instance that is indicated in the code, but of course, this instance does not exist in the client's computer, so the client cannot reach it to do anything.您收到该错误的原因是因为客户端的程序正在尝试查找代码中指示的数据库实例,但是当然,该实例在客户端的计算机中不存在,因此客户端无法访问它任何事物。

Also, please remember to use exception handling.另外,请记住使用异常处理。 We cannot tell what the exact error was (although it is obvious) because your code is only saying "an unhandled exception happened".我们无法确定确切的错误是什么(尽管很明显),因为您的代码只是说“发生了未处理的异常”。 Always wrap your code In try/catch blocks and at the very least have them print the exception to a console so that you can know WHY did a program failed on runtime.始终将您的代码包装在 try/catch 块中,至少让它们将异常打印到控制台,以便您知道程序在运行时失败的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用C#桌面应用程序控制对SQL Server数据库文件的访问 - Controlling access to SQL server database file with C# desktop application 如何在Visual Studio 2010中使用SQL Server 2012数据库打包和部署C#桌面应用程序? - How to package and deploy a C# desktop application with a SQL Server 2012 database in Visual Studio 2010? C#桌面应用程序:SQL Server访问突然变慢 - C# Desktop Application: SQL Server access suddenly gets slow .NET桌面应用程序的体系结构-客户端服务器C#,SQL - Architecture of .NET Desktop Application - Client Server C#, SQL 桌面C#SQL Server(LocalDB)数据库访问模式 - Desktop C# SQL Server (LocalDB) database access patterns C#应用使用SQL服务器数据库 - C# application using SQL Server database 用SQL Server数据库部署C#应用程序? - C# application deployment with sql server database? 有什么方法可以将Power Bi报表和仪表板与SQL Server 2008数据库一起嵌入vb.net或C#桌面应用程序中? - Is there any way to embed power bi reports and dashboards in vb.net or C# desktop application with sql server 2008 database? 如何使用访问数据库发布C#应用程序 - how to publish C# application with the access database 您如何发布或部署您的 C# 桌面应用程序? - How do you publish or deploy your C# desktop application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM