Solved

SQL SERVER instance data location.

Posted on 2013-06-05
3
254 Views
Last Modified: 2013-06-06
Hello All,

I have been asked (instructed) to come up with the code that will provide me with the default data location for a particular server. I am going to allow the user to choose the server and generating a list of servers and databases on the server is not a problem. Once the server is selected I need to retrieve the default data location (file path) for that server. I van not use the SQL Server SMO options. Any suggestions?

Thanks Art
0
Comment
Question by:Nashua58
3 Comments
 
LVL 18

Assisted Solution

by:DarrenD
DarrenD earned 250 total points
ID: 39224927
Hi,

This query should tell you:

SELECT SUBSTRING(filename, 1, CHARINDEX(N'Name of Database.mdf', LOWER(filename)) - 1)
FROM master.dbo.sysdatabases
WHERE name = 'Name of Database'


Cheers,

Darren
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 250 total points
ID: 39225368
Hi,
the above mentioned script will only work if the directory has not been changed after installation as it only returns the location of the master db.
You have to query the registry for this:
http://tenbulls.co.uk/2010/07/08/how-to-set-and-manage-your-sql-server-default-paths/

HTH
Rainer
0
 

Author Closing Comment

by:Nashua58
ID: 39225804
thanks both are working for me
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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