Solved

SQL SERVER instance data location.

Posted on 2013-06-05
3
253 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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