Solved

SQL Server Root Directory Property

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS 2013 - Overlapping reports 2 22
Querying data from 3 SQL tables 2 32
SSIS with VPN COnnection 2 77
SQL Count issue 24 16
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

777 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