Use mapped network drive for addfile command

  • I have a production server with volume a and b. DR server has volume a, not b. I was hoping to be able to map a network drive to a as b.

    Possible?

    I need to add a filegroup and file to production but the dr server (LOG SHIPPING) will not have the volume available when the command passes through log shipping.

  • the command for mapping a drive is fairly straightforward:

    NET USE G: \\UNCPath\d$\ShareFolder /user:domain\username password

    after that is done, i think you might also need to add the trace flag 1807 to allow the SQL instance to use network paths?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I had been using "NET USE j: \\SAMESERVER\C$\SQL\SQL_Data\J /persistent:yes", even to the point of running through a scheduled task in a batch script, as the service account. The service account is not logged onto the machine at any time.

    I was hoping the trace flag would work, but appears to not. Good information to note. Maybe playing with the trace flag at levels above session may give me a better start.

    I had been running USE [master]

    GO

    DBCC TraceON (1807)

    GO

    ALTER DATABASE [DATABASE] ADD FILE

    ( NAME = N'TESTING',

    FILENAME = N'J:\TESTING_Archive.ndf' ,

    SIZE = 3072000KB ,

    FILEGROWTH = 10%) TO FILEGROUP [TestAnother]

    GO

    I had been getting the error of Msg 5133, Level 16, State 1, Line 2

    Directory lookup for the file "J:\LIFT_Data_Archive.ndf" failed with the operating system error 3(The system cannot find the path specified.).

    Msg 5009, Level 16, State 8, Line 2

    One or more files listed in the statement could not be found or could not be initialized.

  • matt this worked 100% for me as an example; the difference here is I used the username parameters for the net use as a user that has permissions on the network;

    from there, i got an error on adding the filegroup, until i set the trace flag:

    exec master.dbo.xp_cmdshell 'NET USE J: \\DEV223\c$\DataFiles /user:disney\lizaguirre NotTheRealPassword /persistent:yes'

    ALTER DATABASE [SandBox] ADD FILE

    ( NAME = N'TESTING',

    FILENAME = N'J:\TESTING_Archive.ndf' ,

    SIZE = 3072KB ,

    FILEGROWTH = 10%)

    /*

    Msg 5110, Level 16, State 2, Line 1

    The file "J:\TESTING_Archive.ndf" is on a network path that is not supported for database files.

    Msg 5009, Level 16, State 8, Line 1

    One or more files listed in the statement could not be found or could not be initialized.

    */

    DBCC TraceON (1807)

    ALTER DATABASE [SandBox] ADD FILE

    ( NAME = N'TESTING',

    FILENAME = N'J:\TESTING_Archive.ndf' ,

    SIZE = 3072KB ,

    FILEGROWTH = 10%)

    /*

    Command(s) completed successfully.

    */

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • AWESOME! Thanks!

    I had not been using xp_cmdshell to execute the net use command. I knew I was getting hung up in permissions but just didn't know where. Well, now I guess I will just really hope that a log shipping restore session won't break and all goes smoothly (save the time of re-doing log shipping). Have been testing on testing server and it's looking clean.

    EXEC sp_configure 'xp_cmdshell', 1

    GO

    RECONFIGURE

    GO

    exec master.dbo.xp_cmdshell 'NET USE.......

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply