gpt4 book ai didi

sql-server - WinForms 应用程序设计——将文档从 SQL Server 移动到文件存储

转载 作者:行者123 更新时间:2023-12-03 16:42:53 24 4
gpt4 key购买 nike

我有一个连接到 SQL Server 的标准 WinForms 应用程序。该应用程序允许用户将当前存储在数据库中的文档上传到使用图像列的表格中。

我需要更改此方法,以便将文档存储为文件,并将指向该文件的链接存储在数据库表中。

使用当前的方法——当用户上传文档时,他们不会知道文档是如何存储的,因为他们连接到数据库,所以他们不需要知道文件的存储位置,也不需要特殊的目录权限等是必须的。如果我为文档设置网络共享,我想避免任何 IT 问题,例如用户必须有权访问此目录才能上传或访问现有文档。

执行此操作有哪些可用选项?我想到了一个临时数据库,文件以与当前方法相同的方式上传到其中,然后在服务器上运行一个进程将这些文件保存到文件存储中。然后可以删除并重新创建该数据库以回收任何空间。有没有更好的方法?

附加信息:我的应用程序没有 Web 服务器元素,所以我认为 WCF 服务是不可能的

最佳答案

您是否首先要将文件从数据库中取出?

如何仍然将它们保存在 SQL Server 中,但使用 FILESTREAM column而不是 IMAGE?

引用自链接:

FILESTREAM enables SQL Server-based applications to store unstructured data, such as documents and images, on the file system. Applications can leverage the rich streaming APIs and performance of the file system and at the same time maintain transactional consistency between the unstructured data and corresponding structured data.

FILESTREAM integrates the SQL Server Database Engine with an NTFS file system by storing varbinary(max) binary large object (BLOB) data as files on the file system. Transact-SQL statements can insert, update, query, search, and back up FILESTREAM data. Win32 file system interfaces provide streaming access to the data.

FILESTREAM uses the NT system cache for caching file data. This helps reduce any effect that FILESTREAM data might have on Database Engine performance. The SQL Server buffer pool is not used; therefore, this memory is available for query processing.

所以你会得到两全其美:
这些文件将作为文件存储在硬盘上(与将它们存储在数据库中相比可能更快),但您不必关心文件共享、权限等。

请注意,您至少需要 SQL Server 2008 才能使用 FILESTREAM

关于sql-server - WinForms 应用程序设计——将文档从 SQL Server 移动到文件存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10636867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com