問題描述
我有一個連接到 SQL Server 的標準 WinForms 應用程序.該應用程序允許用戶使用圖像列將當前存儲在數據庫中的文檔上傳到表格中.
I have a standard WinForms application that connects to a SQL Server. The application allows users to upload documents which are currently stored in the database, in a table using an image column.
我需要更改此方法,以便將文檔存儲為文件,并將指向該文件的鏈接存儲在數據庫表中.
I need to change this approach so the documents are stored as files and a link to the file is stored in the database table.
使用當前的方法 - 當用戶上傳文檔時,他們不受存儲方式的影響,因為他們連接到數據庫,他們不需要知道關于文件存儲位置的任何信息,沒有特殊的目錄權限等是必要的.如果我為文檔設置網絡共享,我希望避免任何 IT 問題,例如用戶必須有權訪問此目錄才能上傳或訪問現有文檔.
Using the current approach - when the user uploads a document they are shielded from how this is stored, as they have a connection to the database they do not need to know anything about where the files are stored, no special directory permissions etc are required. If I set up a network share for the documents I want to avoid any IT issues such as the users having to have access to this directory to upload to or access existing documents.
有哪些選項可以做到這一點?我想有一個臨時數據庫,以與當前方法相同的方式將文檔上傳到其中,然后在服務器上運行一個進程以將這些文件保存到文件存儲中.然后可以刪除并重新創建該數據庫以回收任何空間.有沒有更好的方法?
What are the options available to do this? I thought of having a temporary database where the documents are uploaded to in the same way as the current approach and then a process running on the server to save these to the file store. This database could then be deleted and recreated to reclaim any space. Are there any better approaches?
附加信息:我的應用程序沒有網絡服務器元素,所以我認為 WCF 服務是不可能的
ADDITIONAL INFO: There is no web server element to my application so I do not think a WCF service is possible
推薦答案
您是否有理由首先將文件從數據庫中取出?
Is there a reason why you want to get the files out of the database in the first place?
如何仍然將它們保存在 SQL Server 中,但使用 FILESTREAM
列 而不是 IMAGE
?
How about still saving them in SQL Server, but using a FILESTREAM
column instead of IMAGE
?
引自鏈接:
FILESTREAM 使基于 SQL Server 的應用程序能夠存儲非結構化的文件系統上的數據,例如文檔和圖像.應用可以利用豐富的流 API 和文件的性能同時保持系統之間的事務一致性非結構化數據和相應的結構化數據.
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 將 SQL Server 數據庫引擎與 NTFS 文件集成系統通過將 varbinary(max) 二進制大對象 (BLOB) 數據存儲為文件系統上的文件.Transact-SQL 語句可以插入、更新、查詢、搜索和備份 FILESTREAM 數據.Win32 文件系統接口提供對數據的流式訪問.
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 使用 NT 系統緩存來緩存文件數據.這有助于減少 FILESTREAM 數據可能對數據庫引擎產生的任何影響表現.不使用 SQL Server 緩沖池;因此,這內存可用于查詢處理.
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.
這樣你就可以兩全其美:
文件將作為文件存儲在硬盤上(可能比將它們存儲在數據庫中更快),但您不必關心文件共享、權限等.
So you would get the best out of both worlds:
The files would be stored as files on the hard disk (probabl faster compared to storing them in the database), but you don't have to care about file shares, permissions etc.
請注意,您至少需要 SQL Server 2008 才能使用 FILESTREAM
.
Note that you need at least SQL Server 2008 to use FILESTREAM
.
這篇關于WinForms 應用程序設計——將文檔從 SQL Server 移動到文件存儲的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!