Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server Root Directory Property

Posted on 2008-10-24
5
Medium Priority
?
1,331 Views
Last Modified: 2012-05-05
I am in need of the 'Root Directory' property of SQL Server, due to our users' setups varying from machine to machine.  This has to work with SQL Express.

The serverproperty function does not accept anything which returns the Root Directory, and I'm hoping there is a similar function I could use.

Many thanks
0
Comment
Question by:HatchIT
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22798431
What "ROOT DIRECTORY" are you referring to?
0
 
LVL 1

Author Comment

by:HatchIT
ID: 22798517
My aim is to get the default directory of the data storage location...
eg: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\

If you check the 'Server Properties', Under the 'General' tab ( for example, right click on the server in SQL Server Management Studio, and go to properties )... you can see the root directory specified (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\) and this is the value I was somehow hoping to get ...

I googled and found two viable solutions, one using xp_cmdshell (which is turned off and not an option), and another by querying the registry (which I hope to avoid but will make use of as a last case scenario).
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22798568
This will work for finding where SQL Server is located.  And it will be one directory up from there.

select * from sys.dm_os_loaded_modules
where right(name,12) = 'sqlservr.exe'

But why do you need to determine the default location out of curiousity?
0
 
LVL 1

Author Comment

by:HatchIT
ID: 22798753
We have a script which checks a predefined directory for database backups, usually a dozen or so, and restores each to MSDE.  Since we installed SQL Server Express onto the users' machines, the script fails and aborts during the first restore with the error:
 'Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL\Data\Bid_Process.mdf" failed with the operating system error 3(The system cannot find the path specified.) failed with the operating system error 3(The system cannot find the path specified.'.....  

Creating the missing directory it was looking for (c:\....\MSSQL\Data\) and running the script runs fine.  Since each users' installations may vary (some having MSDE + named instances of SQL Express, or differing combinations), my aim is to Restore with Move option to the root directory of the sql server in use....

Hope that explains it clear enough, if there is something I'm overlooking, don't hesitate to criticize...
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22798790
You can always look up the location of master and put it there.



select * from master.sys.sysfiles
where fileid=1
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question