Physical location of FILESTREAM data

前端 未结 5 529
清酒与你
清酒与你 2021-01-06 07:47

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?

相关标签:
5条回答
  • 2021-01-06 08:10

    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.

    0 讨论(0)
  • 2021-01-06 08:11

    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
    
    0 讨论(0)
  • 2021-01-06 08:26

    --filestream file path

    SELECT col.PathName() AS path FROM tbl
    
    0 讨论(0)
  • 2021-01-06 08:30

    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

    0 讨论(0)
  • 2021-01-06 08:34

    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.

    0 讨论(0)
提交回复
热议问题