Where are my files?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












The DBA run a file relocation script to move the physical Database file from where it was running to I:.



ALTER DATABASE [cro01] MODIFY FILE ( name=cro01,filename=N'i:SQLDatacro01.MDF') 


He take the Database offline ad copy the file.
But for some strange reason he don't finnish the job correctly. We have now mdf files duplicated and we dont know which one is running. How do I know the "real" running location of the files via a Tsql query? Is it posible? I want to avoid checking manually each disk file location against each sys.master_files entry.










share|improve this question









New contributor




Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    1
    down vote

    favorite












    The DBA run a file relocation script to move the physical Database file from where it was running to I:.



    ALTER DATABASE [cro01] MODIFY FILE ( name=cro01,filename=N'i:SQLDatacro01.MDF') 


    He take the Database offline ad copy the file.
    But for some strange reason he don't finnish the job correctly. We have now mdf files duplicated and we dont know which one is running. How do I know the "real" running location of the files via a Tsql query? Is it posible? I want to avoid checking manually each disk file location against each sys.master_files entry.










    share|improve this question









    New contributor




    Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      The DBA run a file relocation script to move the physical Database file from where it was running to I:.



      ALTER DATABASE [cro01] MODIFY FILE ( name=cro01,filename=N'i:SQLDatacro01.MDF') 


      He take the Database offline ad copy the file.
      But for some strange reason he don't finnish the job correctly. We have now mdf files duplicated and we dont know which one is running. How do I know the "real" running location of the files via a Tsql query? Is it posible? I want to avoid checking manually each disk file location against each sys.master_files entry.










      share|improve this question









      New contributor




      Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      The DBA run a file relocation script to move the physical Database file from where it was running to I:.



      ALTER DATABASE [cro01] MODIFY FILE ( name=cro01,filename=N'i:SQLDatacro01.MDF') 


      He take the Database offline ad copy the file.
      But for some strange reason he don't finnish the job correctly. We have now mdf files duplicated and we dont know which one is running. How do I know the "real" running location of the files via a Tsql query? Is it posible? I want to avoid checking manually each disk file location against each sys.master_files entry.







      sql-server alter-database






      share|improve this question









      New contributor




      Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 2 days ago









      Kin

      52k478186




      52k478186






      New contributor




      Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 days ago









      Sergio Branda

      61




      61




      New contributor




      Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Sergio Branda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote













          dbatools to the rescue - use Find-DbaOrphanedFile




          This command searches all directories associated with SQL database files for database files that are not currently in use by the SQL Server instance.



          By default, it looks for orphaned .mdf, .ldf and .ndf files in the rootdata directory, the default data path, the default log path, the system paths and any directory in use by any attached directory.



          You can specify additional filetypes using the -FileType parameter, and additional paths to search using the -Path parameter.




          e.g. Below command will - Connect to sqlserver2014a, authenticating with SQL Server authentication, and searches for orphaned files. Returns server name, local filename, and unc path to file.



          $cred = get-credential -UserName yourUserThatHasAccessToYourServer -Message "Enter correct Password"
          #above will pop up message box to enter the password !
          Find-DbaOrphanedFile -SqlInstance sqlserver2014a -SqlCredential $cred





          share|improve this answer






















          • Thanks a lot! I am testing it.
            – Sergio Branda
            yesterday

















          up vote
          0
          down vote













          You can use the following to find the real physical name



          exec sp_helpdb <your db name>

          -- or
          select * from master.sys.master_files
          where database_id = db_id('<your db name>')





          share|improve this answer




















          • Sorry, this query tell me where it should be, not where it really is. Pf I run the above alter and change the path where the files are running now to a new location, the Database continue to point to the "old" place while the script tell you where it should be. When you take the DB offline and online again, then the DB start using the new path and forget the old location. Of course, you need to copy or move the files to the new location also.
            – Sergio Branda
            yesterday










          • after you alter the database to point its path to a new location, this alter action only changes the metadata info. But I kind of understand you now, what you want to know is where is the real data file location the sql server engine uses after I alter the file location but BEFORE setting the db offline and online again. This is indeed an interesting question.
            – jyao
            yesterday










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "182"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Sergio Branda is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f222661%2fwhere-are-my-files%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote













          dbatools to the rescue - use Find-DbaOrphanedFile




          This command searches all directories associated with SQL database files for database files that are not currently in use by the SQL Server instance.



          By default, it looks for orphaned .mdf, .ldf and .ndf files in the rootdata directory, the default data path, the default log path, the system paths and any directory in use by any attached directory.



          You can specify additional filetypes using the -FileType parameter, and additional paths to search using the -Path parameter.




          e.g. Below command will - Connect to sqlserver2014a, authenticating with SQL Server authentication, and searches for orphaned files. Returns server name, local filename, and unc path to file.



          $cred = get-credential -UserName yourUserThatHasAccessToYourServer -Message "Enter correct Password"
          #above will pop up message box to enter the password !
          Find-DbaOrphanedFile -SqlInstance sqlserver2014a -SqlCredential $cred





          share|improve this answer






















          • Thanks a lot! I am testing it.
            – Sergio Branda
            yesterday














          up vote
          3
          down vote













          dbatools to the rescue - use Find-DbaOrphanedFile




          This command searches all directories associated with SQL database files for database files that are not currently in use by the SQL Server instance.



          By default, it looks for orphaned .mdf, .ldf and .ndf files in the rootdata directory, the default data path, the default log path, the system paths and any directory in use by any attached directory.



          You can specify additional filetypes using the -FileType parameter, and additional paths to search using the -Path parameter.




          e.g. Below command will - Connect to sqlserver2014a, authenticating with SQL Server authentication, and searches for orphaned files. Returns server name, local filename, and unc path to file.



          $cred = get-credential -UserName yourUserThatHasAccessToYourServer -Message "Enter correct Password"
          #above will pop up message box to enter the password !
          Find-DbaOrphanedFile -SqlInstance sqlserver2014a -SqlCredential $cred





          share|improve this answer






















          • Thanks a lot! I am testing it.
            – Sergio Branda
            yesterday












          up vote
          3
          down vote










          up vote
          3
          down vote









          dbatools to the rescue - use Find-DbaOrphanedFile




          This command searches all directories associated with SQL database files for database files that are not currently in use by the SQL Server instance.



          By default, it looks for orphaned .mdf, .ldf and .ndf files in the rootdata directory, the default data path, the default log path, the system paths and any directory in use by any attached directory.



          You can specify additional filetypes using the -FileType parameter, and additional paths to search using the -Path parameter.




          e.g. Below command will - Connect to sqlserver2014a, authenticating with SQL Server authentication, and searches for orphaned files. Returns server name, local filename, and unc path to file.



          $cred = get-credential -UserName yourUserThatHasAccessToYourServer -Message "Enter correct Password"
          #above will pop up message box to enter the password !
          Find-DbaOrphanedFile -SqlInstance sqlserver2014a -SqlCredential $cred





          share|improve this answer














          dbatools to the rescue - use Find-DbaOrphanedFile




          This command searches all directories associated with SQL database files for database files that are not currently in use by the SQL Server instance.



          By default, it looks for orphaned .mdf, .ldf and .ndf files in the rootdata directory, the default data path, the default log path, the system paths and any directory in use by any attached directory.



          You can specify additional filetypes using the -FileType parameter, and additional paths to search using the -Path parameter.




          e.g. Below command will - Connect to sqlserver2014a, authenticating with SQL Server authentication, and searches for orphaned files. Returns server name, local filename, and unc path to file.



          $cred = get-credential -UserName yourUserThatHasAccessToYourServer -Message "Enter correct Password"
          #above will pop up message box to enter the password !
          Find-DbaOrphanedFile -SqlInstance sqlserver2014a -SqlCredential $cred






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          Kin

          52k478186




          52k478186











          • Thanks a lot! I am testing it.
            – Sergio Branda
            yesterday
















          • Thanks a lot! I am testing it.
            – Sergio Branda
            yesterday















          Thanks a lot! I am testing it.
          – Sergio Branda
          yesterday




          Thanks a lot! I am testing it.
          – Sergio Branda
          yesterday












          up vote
          0
          down vote













          You can use the following to find the real physical name



          exec sp_helpdb <your db name>

          -- or
          select * from master.sys.master_files
          where database_id = db_id('<your db name>')





          share|improve this answer




















          • Sorry, this query tell me where it should be, not where it really is. Pf I run the above alter and change the path where the files are running now to a new location, the Database continue to point to the "old" place while the script tell you where it should be. When you take the DB offline and online again, then the DB start using the new path and forget the old location. Of course, you need to copy or move the files to the new location also.
            – Sergio Branda
            yesterday










          • after you alter the database to point its path to a new location, this alter action only changes the metadata info. But I kind of understand you now, what you want to know is where is the real data file location the sql server engine uses after I alter the file location but BEFORE setting the db offline and online again. This is indeed an interesting question.
            – jyao
            yesterday














          up vote
          0
          down vote













          You can use the following to find the real physical name



          exec sp_helpdb <your db name>

          -- or
          select * from master.sys.master_files
          where database_id = db_id('<your db name>')





          share|improve this answer




















          • Sorry, this query tell me where it should be, not where it really is. Pf I run the above alter and change the path where the files are running now to a new location, the Database continue to point to the "old" place while the script tell you where it should be. When you take the DB offline and online again, then the DB start using the new path and forget the old location. Of course, you need to copy or move the files to the new location also.
            – Sergio Branda
            yesterday










          • after you alter the database to point its path to a new location, this alter action only changes the metadata info. But I kind of understand you now, what you want to know is where is the real data file location the sql server engine uses after I alter the file location but BEFORE setting the db offline and online again. This is indeed an interesting question.
            – jyao
            yesterday












          up vote
          0
          down vote










          up vote
          0
          down vote









          You can use the following to find the real physical name



          exec sp_helpdb <your db name>

          -- or
          select * from master.sys.master_files
          where database_id = db_id('<your db name>')





          share|improve this answer












          You can use the following to find the real physical name



          exec sp_helpdb <your db name>

          -- or
          select * from master.sys.master_files
          where database_id = db_id('<your db name>')






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          jyao

          2,339419




          2,339419











          • Sorry, this query tell me where it should be, not where it really is. Pf I run the above alter and change the path where the files are running now to a new location, the Database continue to point to the "old" place while the script tell you where it should be. When you take the DB offline and online again, then the DB start using the new path and forget the old location. Of course, you need to copy or move the files to the new location also.
            – Sergio Branda
            yesterday










          • after you alter the database to point its path to a new location, this alter action only changes the metadata info. But I kind of understand you now, what you want to know is where is the real data file location the sql server engine uses after I alter the file location but BEFORE setting the db offline and online again. This is indeed an interesting question.
            – jyao
            yesterday
















          • Sorry, this query tell me where it should be, not where it really is. Pf I run the above alter and change the path where the files are running now to a new location, the Database continue to point to the "old" place while the script tell you where it should be. When you take the DB offline and online again, then the DB start using the new path and forget the old location. Of course, you need to copy or move the files to the new location also.
            – Sergio Branda
            yesterday










          • after you alter the database to point its path to a new location, this alter action only changes the metadata info. But I kind of understand you now, what you want to know is where is the real data file location the sql server engine uses after I alter the file location but BEFORE setting the db offline and online again. This is indeed an interesting question.
            – jyao
            yesterday















          Sorry, this query tell me where it should be, not where it really is. Pf I run the above alter and change the path where the files are running now to a new location, the Database continue to point to the "old" place while the script tell you where it should be. When you take the DB offline and online again, then the DB start using the new path and forget the old location. Of course, you need to copy or move the files to the new location also.
          – Sergio Branda
          yesterday




          Sorry, this query tell me where it should be, not where it really is. Pf I run the above alter and change the path where the files are running now to a new location, the Database continue to point to the "old" place while the script tell you where it should be. When you take the DB offline and online again, then the DB start using the new path and forget the old location. Of course, you need to copy or move the files to the new location also.
          – Sergio Branda
          yesterday












          after you alter the database to point its path to a new location, this alter action only changes the metadata info. But I kind of understand you now, what you want to know is where is the real data file location the sql server engine uses after I alter the file location but BEFORE setting the db offline and online again. This is indeed an interesting question.
          – jyao
          yesterday




          after you alter the database to point its path to a new location, this alter action only changes the metadata info. But I kind of understand you now, what you want to know is where is the real data file location the sql server engine uses after I alter the file location but BEFORE setting the db offline and online again. This is indeed an interesting question.
          – jyao
          yesterday










          Sergio Branda is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Sergio Branda is a new contributor. Be nice, and check out our Code of Conduct.












          Sergio Branda is a new contributor. Be nice, and check out our Code of Conduct.











          Sergio Branda is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f222661%2fwhere-are-my-files%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay