FILESTREAM 数据的物理位置

发布于 2024-08-19 14:53:57 字数 81 浏览 1 评论 0原文

我如何知道刚刚插入数据库的 FILESTREAM 数据的物理位置(以便我可以在 Windows 资源管理器中看到它)路径?

How could I know the physical location (so I can see it in Windows Explorer) path of a FILESTREAM data that I've just inserted into DB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

彩扇题诗 2024-08-26 14:53:57

为此有一个选项:方法PhysicalPathName()。如果您现在使用的是 SQL Server 2012 或更高版本,此代码将适合您:

SELECT stream.PhysicalPathName() AS 'Path' FROM Media
OPTION (QUERYTRACEON 5556)

对于 SQL Server 2008/2008 R2,您将需要为整个实例启用跟踪标志 5556:

DBCC TRACEON (5556, -1)
GO

或者为您调用 PhysicalPathName( 的特定连接) ) 方法:

DBCC TRACEON (5556, -1)
GO

There is one option for this: method PhysicalPathName(). If you are on SQL Server 2012 or upper now, this code will work for you:

SELECT stream.PhysicalPathName() AS 'Path' FROM Media
OPTION (QUERYTRACEON 5556)

For SQL Server 2008/2008 R2 you will need to enable trace flag 5556 for the whole instance:

DBCC TRACEON (5556, -1)
GO

or for the particular connection in which you are calling PhysicalPathName() method:

DBCC TRACEON (5556, -1)
GO
じее 2024-08-26 14:53:57

我知道这是一篇较旧的帖子,但由于它在谷歌搜索排名中仍然很高,我想我应该发布一个答案。当然,在更高版本的 SQL 中(我在 2008 年没有尝试过),您可以运行以下查询:

SELECT      t.name AS 'table',
            c.name AS 'column', 
            fg.name AS 'filegroup_name', 
            dbf.type_desc AS 'type_description',
            dbf.physical_name AS 'physical_location'
FROM        sys.filegroups fg
INNER JOIN  sys.database_files dbf
ON          fg.data_space_id = dbf.data_space_id
INNER JOIN  sys.tables t
ON          fg.data_space_id = t.filestream_data_space_id
INNER JOIN  sys.columns c
ON          t.object_id = c.object_id
AND         c.is_filestream = 1

来源

I know this is an older post but as it still comes up high in the Google search rankings I thought I'd post an answer. Certainly in later versions of SQL (I've not tried this on 2008) you can run the following query:

SELECT      t.name AS 'table',
            c.name AS 'column', 
            fg.name AS 'filegroup_name', 
            dbf.type_desc AS 'type_description',
            dbf.physical_name AS 'physical_location'
FROM        sys.filegroups fg
INNER JOIN  sys.database_files dbf
ON          fg.data_space_id = dbf.data_space_id
INNER JOIN  sys.tables t
ON          fg.data_space_id = t.filestream_data_space_id
INNER JOIN  sys.columns c
ON          t.object_id = c.object_id
AND         c.is_filestream = 1

Source

一花一树开 2024-08-26 14:53:57

正如 Pawel 所提到的,使用 Windows 资源管理器访问 FILESTREAM 文件并不是一个好主意。如果您仍然决心继续探索这一点,以下提示可能会有所帮助。

FILESTREAM 文件名实际上是创建文件时数据库事务日志中的日志序列号。 Paul Randal 在这篇文章中对此进行了解释。因此,一种选择是找出日志序列号,并在文件流数据容器中查找以该序列号命名的文件。

As Pawel has mentioned, it is not a good idea to access the FILESTREAM files using Windows Explorer. If you are still determined to go ahead and explore this, the following tip might help.

The FILESTREAM file names are actually the log-sequence number from the database transaction log at the time the files were created. Paul Randal has explained it in this post. So One option is to find out the log sequence number and look for a file named after that in the file stream data container.

浪漫人生路 2024-08-26 14:53:57

首先,您需要了解 FileStream 存储在托管 SQL Server 2008 数据库的服务器上。如果您有 DBA,请询问他们在哪里创建 FileStream。当然,您随后需要服务器的权限才能导航服务器以查看目录。您也无法以任何方式操作这些文件,但您将能够看到它们。大多数 DBA 不会热衷于让您知道 FileStream 所在的位置。

但是,您可以通过其他几种方式获取该路径。我想到的一种方法是选择 FileStream 字段的 PathName()。假设FileStream启用的字段是ReportData,并且它所在的表是TblReports。以下 t-sql 语法将生成该位置的 UNC:

select top 1 ReportData.PathName(0)
from dbo.datReport

我相信您还可以通过企业管理器通过其他方式获取该路径,但我现在忘记了如何操作。

First you need to understand that the FileStream is being stored on the server hosting your SQL Server 2008 database. If you have a DBA, ask them where they created it the FileStream at. Of course, you'll then need rights to the server to navigate it to see the directories. You won't be able to manipulate the files in any way either, but you will be able to see them. Most DBA's won't be keen on letting you know where the FileStream is located at.

However, you can get at the path by a few other means. One way that comes to mind is by selecting upon the PathName() of the FileStream field. Assume that the FileStream enabled field is ReportData, and the table in which it resides is TblReports. The following t-sql syntax will yield an UNC to the location:

select top 1 ReportData.PathName(0)
from dbo.datReport

I believe you can also get at the path by other means through enterprise manager, but I forget how to at the moment.

想挽留 2024-08-26 14:53:57

--filestream 文件路径

SELECT col.PathName() AS path FROM tbl

--filestream file path

SELECT col.PathName() AS path FROM tbl
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文