Solved

SQL Server Root Directory Property

Posted on 2008-10-24
5
1,265 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 125 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now