?
Solved

SQL SERVER instance data location.

Posted on 2013-06-05
3
Medium Priority
?
257 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
[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 Comments
 
LVL 18

Assisted Solution

by:DarrenD
DarrenD earned 1000 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 1000 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

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 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