Solved

SQL SERVER instance data location.

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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 …
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

13 Experts available now in Live!

Get 1:1 Help Now