使用 C# 在客户端计算机和服务器计算机数据库之间传输文件
我在网络中的服务器计算机上有这个 SQL 数据库,我希望任何客户端计算机都能够相应地向数据库上传和下载文件,其中文件将保存到服务器计算机文件系统及其元数据中将存储在数据库中。
执行该任务的最佳方法是什么?我该如何使用 C# winform 应用程序来实现它? 提前谢谢@_@
I have this SQL database on a server machine in a network and I want any of the client machines to be able to upload and download files to and from the database accordingly where the files will be saved to the server machine file system and their meta data will be stored in the database.
What is the best method to perform that task? and how shall I implement it using C# winform application?
thx in advance @_@
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要将文件存储在数据库中?文件系统(我确信相关服务器也有)更适合保存和提供文件。
如果文件必须位于数据库中,那么您可能只想将它们存储在 blob 字段中。当然,还应该将其他字段添加到表中,其中包含有关文件的数据。文件名、文件类型,如果您不想动态地从 blob 中计算文件大小,可能还有上传文件的用户、上传时间等。
此时您将与它就像应用程序中的任何其他数据库记录一样(为简洁起见,跳过对此的解释,不乏有关该主题的教程),并具有在 Blob 数据的字节数组之间进行转换的附加步骤。此外,不乏示例。
但我必须回到我最初的问题。为什么要把文件放在关系数据库中?
Why do you want the files to be stored in a database? A file system (which I'm sure the server in question also has) is much more suited to keeping and serving files.
If the files must be in the database, then you'd probably just want to store them in a blob field. Additional fields should be added to the table with data about the files, of course. File name, file type, maybe file size if you don't want to have to calculate it from the blob on the fly, maybe the user who uploaded it, the time it was uploaded, etc.
At that point you'd interact with it just like any other database record in your application (skipping explanation of that for brevity, there's no shortage of tutorials on the subject), with the additional step of converting to and from byte arrays for the blob data. Also, no shortage of examples.
But I have to drive back to my original question. Why put files in a relational database?