Solved

SQL Server Root Directory Property

Posted on 2008-10-24
5
1,284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

632 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