Solved

SQL Server Root Directory Property

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculate values in an array 18 35
Updating a table from a temp table 4 29
Need SQL that flips  value 5 19
ebay table structure 2 14
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

867 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