How to obtain actual file name of a FILESTREAM file.

When a file is added to a FILESTREAM Blob field in SQL Server 2008 the file is renamed to something like 0000001c-0000019c-0004. Is there a way to retrieve this file name after a file is added?  I thought that [BLOB_Field].PathName() was promising
but this turns out to be some sort of virtual filepath that is only used when accessing the file through the filesystem and not via T-SQL. Any ideas?

Many Thanks to Kevin and Jacob, from your help I've been able to whip up a solution. It hasn't been throughly tested but seems to be what I'm looking for.
If you want to use this solution, you'll need to add the following Stored Procedures to your FILESTREAM database.
CREATE
PROCEDURE
[dbo].[procDBCC_PAGE]
@db_name varchar
(500),
@filenum INT
@pagenum INT
AS
BEGIN
SET
NOCOUNT
ON
DBCC
TRACEON (3604);
DBCC
PAGE (@db_name, @filenum, @pagenum, 3) WITH
TABLERESULTS;
SET
NOCOUNT
OFF
END
GO
CREATE
PROCEDURE
[dbo].[procFindLogSequenceNumber]
@TableName varchar
(500),
@FileLedgerID varchar
(500), --INT Causes error "Conversion failed when converting the varchar value '0x08166000' to data type int"
@LogSequenceNumber varchar
(500) OUTPUT
AS
SET
NOCOUNT
ON
DECLARE
@db_name varchar
(500)
DECLARE
@filenum INT
DECLARE
@pagenum INT
DECLARE
@parent_object varchar
(500)
SET
@db_name = db_name
CREATE
TABLE
#AllocationMetadata ([filenum] INT
, [pagenum] INT
INSERT
#AllocationMetadata ([filenum], [pagenum]) EXECUTE
sp_AllocationMetadata_FileNum_PageNum @TableName
--My Primary Key ID column is named FileLedgerID
SET
@filenum = (SELECT
TOP
1 [filenum] FROM
#AllocationMetadata)
SET
@pagenum = (SELECT
TOP
1 [pagenum] FROM
#AllocationMetadata)
CREATE
TABLE
#DBCC_PAGE_Output ([ParentObject] varchar
(MAX
), [Object] varchar
(MAX
), [Field] varchar
(MAX
), [VALUE] varchar
(MAX
INSERT
#DBCC_PAGE_Output ([ParentObject], [Object], [Field], [VALUE]) EXECUTE
procDBCC_PAGE @db_name, @filenum, @pagenum
SET
@parent_object = (SELECT
TOP
1 [ParentObject] FROM
#DBCC_PAGE_Output WHERE
[Field] = 'FileLedgerID'
AND
[VALUE] = @FileLedgerID)
--CreateLSN field Only
SET
@LogSequenceNumber = (SELECT
[VALUE] FROM
#DBCC_PAGE_Output WHERE
[ParentObject] = @parent_object AND
[Field] = 'CreateLSN'
DROP
TABLE
#AllocationMetadata
DROP
TABLE
#DBCC_PAGE_Output
SET
NOCOUNT
OFF
GO
You'll need to add the following Stored Procedure to your 'master' database. Don't forgo the
sys.sp_MS_marksystemobject step, as it won't work without it.
CREATE
PROCEDURE
[dbo].[sp_AllocationMetadata_FileNum_PageNum]
@object VARCHAR
(128) = NULL
AS
SELECT
CONVERT
(VARCHAR
(6),
CONVERT
(INT
, SUBSTRING
(sa.first_page, 6, 1) +
SUBSTRING
(sa.first_page, 5, 1))) AS
[filenum],
CONVERT
(VARCHAR
(20),
CONVERT
(INT
, SUBSTRING
(sa.first_page, 4, 1) +
SUBSTRING
(sa.first_page, 3, 1) +
SUBSTRING
(sa.first_page, 2, 1) +
SUBSTRING
(sa.first_page, 1, 1))) AS
[pagenum]
-- sp.object_id AS [Object_ID],
-- OBJECT_NAME (sp.object_id) AS [Object Name],
-- sp.index_id AS [Index ID],
-- sa.allocation_unit_id AS [Alloc Unit ID],
-- sa.type_desc AS [AllocUnitType],
-- '(' + CONVERT (VARCHAR (6),
-- CONVERT (INT, SUBSTRING (sa.first_page, 6, 1) +
-- SUBSTRING (sa.first_page, 5, 1))) +
-- ':' + CONVERT (VARCHAR (20),
-- CONVERT (INT, SUBSTRING (sa.first_page, 4, 1) +
-- SUBSTRING (sa.first_page, 3, 1) +
-- SUBSTRING (sa.first_page, 2, 1) +
-- SUBSTRING (sa.first_page, 1, 1))) +
-- ')' AS [First Page],
--sa.total_pages AS [Total Pages],
-- '(' + CONVERT (VARCHAR (6),
-- CONVERT (INT,
-- SUBSTRING (sa.root_page, 6, 1) +
-- SUBSTRING (sa.root_page, 5, 1))) +
-- ':' + CONVERT (VARCHAR (20),
-- CONVERT (INT,
-- SUBSTRING (sa.root_page, 4, 1) +
-- SUBSTRING (sa.root_page, 3, 1) +
-- SUBSTRING (sa.root_page, 2, 1) +
-- SUBSTRING (sa.root_page, 1, 1))) +
-- ')' AS [Root Page],
-- '(' + CONVERT (VARCHAR (6),
-- CONVERT (INT,
-- SUBSTRING (sa.first_iam_page, 6, 1) +
-- SUBSTRING (sa.first_iam_page, 5, 1))) +
-- ':' + CONVERT (VARCHAR (20),
-- CONVERT (INT,
-- SUBSTRING (sa.first_iam_page, 4, 1) +
-- SUBSTRING (sa.first_iam_page, 3, 1) +
-- SUBSTRING (sa.first_iam_page, 2, 1) +
-- SUBSTRING (sa.first_iam_page, 1, 1))) +
-- ')' AS [First IAM Page]
FROM
sys.system_internals_allocation_units AS
sa,
sys.partitions AS
sp
WHERE
sa.container_id = sp.partition_id
AND
sp.object_id =
(CASE
WHEN
(@object IS
NULL
THEN
sp.object_id
ELSE
OBJECT_ID
(@object)
END
AND
sa.type_desc = 'IN_ROW_DATA'
GO
EXEC
sys.sp_MS_marksystemobject sp_AllocationMetadata_FileNum_PageNum;
GO
And here's what I use in VBA to access the LogSequenceNumber.  FileLedgerID is the ID column of the data only table that stores the original filename, etc. This is also stored in the FILESTREAM table as a foreign key.
Public
Function
Test_procFindLogSequenceNumber(lngFileLedgerID as Long)
On
Error
GoTo
ErrorHandler
Dim
cmd As
New
ADODB.Command
Set
cnn_Public_FILESTREAM = Nothing
If
cnn_Public_FILESTREAM Is
Nothing
Then
Call
funOpenOrRefreshADOSQLConnection_FILESTREAM
cmd.ActiveConnection = cnn_Public_FILESTREAM 'This is my ADO connection to the FILESTREAM database, you'll have to do your own.
cmd.CommandText = "procFindLogSequenceNumber"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append cmd.CreateParameter("@TableName"
, adLongVarChar, adParamInput, 500, "tblFileLedger_FILESTREAM"
cmd.Parameters.Append cmd.CreateParameter("@FileLedgerID"
, adInteger, adParamInput, , lngFileLedgerID)
cmd.Parameters.Append cmd.CreateParameter("@LogSequenceNumber"
, adVarWChar, adParamOutput, 500)
cmd.Execute , , adExecuteNoRecords
Debug.Print cmd.Parameters("@LogSequenceNumber"
ExitProcedure:
Set
cmd = Nothing
Exit
Function
ErrorHandler:
MsgBox Err.Description
Resume
ExitProcedure
End
Function
And here's what I use to convert the LSN into the exact File name.
Private
Function
funFileNameFromFile_LSN(strBLOB_File_LSN_fun As
String
) As
String
On
Error
GoTo
ErrorHandler
Dim
intPositionOfFirstSpace
'eg. 00000068:000008b0:0003 (104:2224:3)
'Replace colons with dashes
strBLOB_File_LSN_fun = Replace(strBLOB_File_LSN_fun, ":"
'Get position of first space character
intPositionOfFirstSpace = InStr(strBLOB_File_LSN_fun, " "
'Contract string to characters before the first space
funFileNameFromFile_LSN = Left(strBLOB_File_LSN_fun, intPositionOfFirstSpace - 1)
ExitProcedure:
Exit
Function
ErrorHandler:
MsgBox Err.Description
Resume
ExitProcedure
End
Function
I'm very grateful for the advice given here, but I think there still might be a legitimate reason to store the new file name that is created by SQL Server 2008. For instance, your MDF file might become corrupted beyond repair AND you have no backup. Stranger
things have happened. In this case, you would still have your important files available on the server (named like 00000068-000008b0-0003) but you'd be unable to salvage them. You could use trial and error, I suppose (ie. Try adding .doc to the file names and
see what works), but this would be unworkable as soon as you've got files in their hundreds.
Maybe this is just paranoia. Nevertheless I hope this can be of assistance to others.
Thanks again Kevin and Jacob.

Similar Messages

  • How do you change the name of a folder/file on an expansion drive

    How do you change the name of a folder/file on an expansion drive or external hard drive?

    The same way you change it on the internal drive; click on the name and wait a second or two for the field to drop into editing mode, then just type the new name. Or Get Info on the file/folder and change the name there.
    Regards.

  • How write the Outbound file name in the Inbound file

    Friends,
    I have a scenario like this.
    Outbout filename - sample.txt
    In sample.txt, i have having data like 20
    Inbound filename - vivek.txt
    i need data the like sample, 20
    (NOTE: sample is the outbound file)
    How to get this scenario.
    Thanks in advance.
    regards,
    Vivek.

    Hi Vivek,
      If your PI is of SP14 and more you have an option called Adapter Specific Message Attributes.(ASMA) in communicatoin channel configurtaion, Which will help you in capturing the Sender file name during runtime.
    So you will have to enable that option (ASMA) in Commchannel and capture file name  in UDF using Java Code with the help of sap related API and map it to the target field which u would like to get populated.
    follow the thread it has the discussion about acessing the Source file name.
       Re: Getting file directory using dynamic configuration:Code needed
    Thanks,
    Ram.

  • How do I print the file name of a PDF file?

    How do I print the file name of a PDF file?

    In the print dialog under Advanced you can specify this.

  • I have a keynote presentation that i built a while ago. How do identify the file names of the video files that are in the presentation?

    I have a keynote presentation that i built a while ago. How do i now identify the file names of the video files that are in the presentation?

    With your presentation open, click on each movie element and read the name in the Metrics Inspector > File Info.

  • How to find the dsn name from an *.rpd file provided?

    How to find the dsn name from an *.rpd file provided? All the ODBC details which would require to run your dashboard.

    Hi
    DSN name is not a part of .rpd file. So There is no information about DSN name in .rpd file.
    Thanks
    Siddhartha P

  • When someone other than myself downloads an image from my web album, a dynamically generated file name replaces the original file name.  How I can prevent the original file name being replaced during the downloading process?

    When someone other than myself downloads an image from my web album, a dynamically generated file name replaces the original file name.  How I can prevent the file name being changed during this downloading process?

    Hi Glenyse,
    Here are my steps.
    1.  I upload multiple image (jpg) files onto my photo album.
    2.  I select the "sharing" by email option for this album.
    3.  I enter the recipient's email address.
    4.  The recipient receives my message and clicks on the link.
    5.  The recipient accesses my photo album and clicks on one of the images.
    6.  The image opens up to its own screen.
    7.  The recipient selects the "download" and then save file option.
    Here is the part I do not understand.  For some reason, during this "download" process, the original name which I have given to the file is replaced by different name.  So I was hoping that someone knows how to prevent the file name from being changed during the "download and save" process.
    Much appreciated if you can help me find a solution to this problem.
    Mary  

  • How do we change the name of a sound file once it is in the session?

    how do we change the name of a sound file once it is in the session?
    Thanks
    Steve z

    The only way that you can rename the audio file from within Audition is to do a Save As from the Waveform view AFAIAA. You can rename clips by clicking in the name box at the top of the Properties window or by right clicking on the clip and selecting Rename from the drop down menu (this will automatically open the Properties window if it isn't already open).

  • Error Occurred While Converting the file"name of song" The file name.......

    I get this message when I try to import some CD's to my library.
    A window pops up and says
    Error occurred while converting the file "name of song"
    The file name was invalid or to long.
    Anyone else ever get this message, and how can you import CD's???????

    I have had this exact same problem. I'm not sure how to fix it...

  • Get File name of the inbound file during mapping

    Scenario: to read the file name of the inbound file (which has date required for the mapping) during runtime.
    The requirement is to read the date of the inbound file (passed to the XI pipline by the file adapter) and populate the same in the outbound mapping structure.
    Any idea about how to do this?
    (I went through few options of using java.util.map. not successful yet)

    Hi Anand,
    I posted the same question a time ago, without any help....
    Can I find out the full filename of input file in message mapping?
    Posted: Nov 23, 2004 1:00 PM
    I have in XI 2.0 the following scenario :
    In the inbound fileadapter I read my input file. The filename of the input file is part fixed, part variable (Like INDATA01.txt, INDATA03.txt, etc).
    So in my Adapterconfiguration, I specify the filename with a wildcard (INDATA*.txt).
    What I now want to do, is in my Message Mapping use the full filename , so I can do something different for every filenumber. Is there a way where I can get the full filename available in my message mapping (I did not find the filename in the XML in the message trace).

  • Log4j - issue in configuring the file name for daily rolling file adapter

    We have configured the log4j properties. We want to create back-up of log file each hour. The file name of the log file is MyApp.log and as per the below configuration after each hour backup file is created as
    MyApp.log<<time>>
    but we want that file should be created in follogin format
    MyApp<<time>>.log
    Below are the log4j properties configured, please let us know, what should be the correct option to create the filename in desired format.
    # Set root logger level to DEBUG and its only appender to MyApp.
    log4j.rootLogger=DEBUG, MyApp
    log4j.appender.MyApp=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.MyApp.File=D:/logs/MyApp.log
    log4j.appender.MyApp.DatePattern='.'yyyy-MM-dd-HH
    log4j.appender.MyApp.Append=true
    log4j.appender.MyApp.layout=org.apache.log4j.PatternLayout
    log4j.appender.MyApp.layout.ConversionPattern=[%d{yyyy-MM-dd} %d{HH:mm:ss z}] %m%n

    yes you can use /SAPDMC/SAP_LSMW_IMPORT_TEXTS via LSMW
    In the SAP system, there is no uniform rule for the structure of the actual text key Textname. However, in order to be able to maintain the structures and fields, you have to know what the structure of text name as well as the values for text object and text ID are.
    Procedure
           1.      Display a text of the required text type.
           2.      Branch to the editor.
           3.      Choose Goto > Header.
    The Text header dialog box appears.
    Result
    In the Text header dialog box, you gather the required information.

  • Question about pass file name and path to file write adapter

    I need to pass file name and path to file adapter for write. I got partial answers from thread Re: Get File name using File Adapter , but seems InboundHeader_msg or outboundHeader_msg only takes file name, how do I pass file directory?
    since I still have to specify file format (like xxx_%xx%.txt) in the file adapter wizard. Will this name conflict with what the name defined in InboundHeader_msg ?
    Similarly, how can I pass a file name and path to a file synchread adapter?
    Thanks,
    Message was edited by:
    user531689

    Just overwrite the filename in the WSDL file that was generated

  • Different log file name in the Control file of SQL Loader

    Dear all,
    I get every day 3 log files with ftp from a Solaris Server to a Windows 2000 Server machine. In this Windows machine, we have an Oracle Database 9.2. These log files are in the following format: in<date>.log i.e. in20070429.log.
    I would like to load this log file's data to an Oracle table every day and I would like to use SQL Loader for this job.
    The problem is that the log file name is different every day.
    How can I give this variable log file name in the Control file, which is used for the SQL Loader?
    file.ctl
    LOAD DATA
    INFILE 'D:\gbal\in<date>.log'
    APPEND INTO TABLE CHAT_SL
    FIELDS TERMINATED BY WHITESPACE
    TRAILING NULLCOLS
    (SL1 DATE "Mon DD, YYYY HH:MI:SS FF3AM",
    SL2 char,
    SL3 DATE "Mon DD, YYYY HH:MI:SS FF3AM",
    SL4 char,
    SL5 char,
    SL6 char,
    SL7 char,
    SL8 char,
    SL9 char,
    SL10 char,
    SL11 char,
    SL12 char,
    SL13 char,
    SL14 char,
    SL15 char)
    Do you have any better idea about this issue?
    I thought of renaming the log file to an instant name, such as in.log, but how can I distinguish the desired log file, from the other two?
    Thank you very much in advance.
    Giorgos Baliotis

    I don't have a direct solution for your problem.
    However if you invoke the SQL loader from an Oracle stored procedure, it is possible to dynamically set control\log file.
    # Grant previleges to the user to execute command prompt statements
    BEGIN
    dbms_java.grant_permission('bc4186ol','java.io.FilePermission','C:\windows\system32\cmd.exe','execute');
    END;
    * Procedure to execute Operating system commands using PL\SQL(Oracle script making use of Java packages
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    try {
    String[] finalCommand;
    finalCommand = new String[4];
    finalCommand[0] = "C:\\windows\\system32\\cmd.exe";
    finalCommand[1] = "/y";
    finalCommand[2] = "/c";
    finalCommand[3] = command;
    final Process pr = Runtime.getRuntime().exec(finalCommand);
    new Thread(new Runnable() {
    public void run() {
    try {
    BufferedReader br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String buff = null;
    while ((buff = br_in.readLine()) != null) {
    System.out.println("Process out :" + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    catch (IOException ioe) {
    System.out.println("Exception caught printing process output.");
    ioe.printStackTrace();
    }).start();
    new Thread(new Runnable() {
    public void run() {
    try {
    BufferedReader br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    String buff = null;
    while ((buff = br_err.readLine()) != null) {
    System.out.println("Process err :" + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    catch (IOException ioe) {
    System.out.println("Exception caught printing process error.");
    ioe.printStackTrace();
    }).start();
    catch (Exception ex) {
    System.out.println(ex.getLocalizedMessage());
    public static boolean isWindows() {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
    return true;
    else
    return false;
    * Oracle wrapper to call the above procedure
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    * Now invoke the procedure with an operating system command(Execyte SQL-loader)
    * The execution of script would ensure the Prod mapping data file is loaded to PROD_5005_710_MAP table
    * Change the control\log\discard\bad files as apropriate
    BEGIN
    Host_Command (p_command => 'sqlldr system/tiburon@orcl control=C:\anupama\emp_join'||1||'.ctl log=C:\anupama\ond_lists.log');
    END;Does that help you?
    Regards,
    Bhagat

  • Flat file connection: The file name "\server\share\path\file.txt" specified in the connection was not valid

    I'm trying to execute a SSIS package via SQL agent with a flat file source - however it fails with Code: 0xC001401E The file name "\server\share\path\file.txt" specified in the connection was not valid.
    It appears that the problem is with the rights of the user that's running the package (it's a proxy account). If I use a higher-privelege account (domain admin) to run the package it completes successfully. But this is not a long-term solution, and I can't
    see a reason why the user doesn't have rights to the file. The effective permissions of the file and parent folder both give the user full control. The user has full control over the share as well. The user can access the file (copy, etc) outside the SSIS
    package.
    Running the package manually via DTExec gives me the same error - I've tried 32 and 64bit versions with the same result. But running as a domain admin works correctly every time.
    I feel like I've been beating my head against a brick wall on this one... Is there some sort of magic permissions, file or otherwise, that are required to use a flat file target in an SSIS package?

    Hi Rossco150,
    I have tried to reproduce the issue in my test environment (Windows Server 2012 R2 + SQL Server 2008 R2), however, everything goes well with the permission settings as you mentioned. In my test, the permissions of the folders are set as follows:
    \\ServerName\Temp  --- Read
    \\ServerName\Temp\Source  --- No access
    \\ServerName\Temp\Source\Flat Files --- Full control
    I suspect that your permission settings on the folders are not absolutely as you said above. Could you double check the permission settings on each level of the folder hierarchy? In addition, check the “Execute as user” information from job history to make
    sure the job was running in the proxy security context indeed. Which version of SSIS are you using? If possible, I suggest that you install the latest Service Pack for you SQL Server or even install the latest CU patch. 
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • Temp File Name Schema in Receiver File adapter

    Hi,
    I have a scenario where i have to write the file in the temperaory location before writing it to the FTP loacation, I have selected the Processing Parameter as "Use Temperory File" but when the file gets created it is padded with the Message Id, is thr any option to get the file name as the temp file name without the Message Id or timestamp.
    Please let me know if any one has come across such scenario.
    thankx,
    shree

    Hi,
    Under Write Mode, specify whether the target file is to be written directly in the specified directory. If an additional step is to be added using a temporary file, choose Use Temporary File.
    You can specify a naming scheme for the temporary file under Temporary File Name Scheme.
    This schema is used to determine the prefix and extension of the temporary file; to ensure a unique file name, a time stamp is also added to the name during processing.
    The schema xitemp.tmp, for example, results in the file name xitemp<timestamp>.tmp
    So you have to customise the file name in schema.
    see below link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm
    Regards
    Chilla

Maybe you are looking for