Showing posts with label directory. Show all posts
Showing posts with label directory. Show all posts

Wednesday, March 21, 2012

How to find the SQL Server install directory from tsql

How do we find the SQL Server install directory using a T-sql command or from command prompt?

Thanks,
Vivek
You can find the path (with and without filename) to master.mdf from the master_files system view, if that's enough:

Code Snippet

select physical_name
from master.sys.master_files
where name = 'master';

declare @.tail int
set @.tail = (
select charindex('\',reverse(physical_name))
from master.sys.master_files
where name = 'master'
)
select substring(physical_name,1,len(physical_name)-@.tail)
from master.sys.master_files
where name = 'master';

The installation directory is a registry key, and a batch file to dig it out is suggested here: http://weblogs.asp.net/jgalloway/archive/2006/10.aspx. (I didn't try it, but there's a link to another page noting that the white space after delims is a tab followed by a space.)

Steve Kass
Drew University
http://www.stevekass.com
|||

All you need is in the link below but in C#. It is 23pages long so read it but you need admin permissions if it is a server. Hope this helps.

http://msdn2.microsoft.com/en-us/library/bb264562.aspx

|||The system databases are not under the SQL Server installed directory. They are in a different drive. If this is the case how do i get the install directory?
|||

One more approach on T-SQL itself..

Code Snippet

Create Table #Data

(

path Varchar(max)

)

Insert Into #Data

Exec xp_cmdshell 'path'

Declare @.Paths Varchar(max)

Set @.Paths = ';'

Select @.Paths = @.Paths + Replace(Path,'Path=','') From #Data Where Path is NOT NULL

select @.Paths = @.Paths + ';'

Create table #Number

(

Number Int

)

Declare @.i as Int

Set @.i = 1

While @.i<len(@.Paths)

Begin

Insert Into #Number Select @.i;

Set @.i=@.i+1

End

Select

Replace(Replace(paths,'\Tools\BINN\',''),'\Tools\BINN','') [SQL Server Paths]

From

(

Select

Substring(@.Paths,Number,Charindex(';',@.Paths,Number)-Number) Paths

From

#Number

Where

Substring(@.paths,Number-1,1) = ';'

) as Data

Where Paths Like '%Microsoft SQL Server%'

Drop Table #Number;

Drop Table #Data;

|||

One more easy approach .. using undocumented system procedure..

Code Snippet

Declare @.Path as varchar(100);

Set @.Path = NULL

Exec master..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Microsoft SQL Server\70\Tools\ClientSetup', 'SQLPath', @.Path OUTPUT

Select @.Path as [Sql Server 7.0 path]

Set @.Path = NULL

Exec master..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Microsoft SQL Server\80\Tools\ClientSetup', 'SQLPath', @.Path OUTPUT

Select @.Path as [Sql Server 2000 path]

Set @.Path = NULL

Exec master..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup', 'SQLPath', @.Path OUTPUT

Select @.Path as [Sql Server 2005 path]

Set @.Path = NULL

Exec master..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup', 'SQLPath', @.Path OUTPUT

Select @.Path as [Sql Server KATMAI path]

|||

You could use SMO and write a CLR function that would return the value.

It could be more reliable (thinking permission issues) than reading the registry with xp_regread.

For an idea, refer to Books Online, Topic: 'RootDirectory property'

There are several properties of the Server object that one could find useful.

|||Thanks Manivannan it works!!!
|||

The link below contains a SQLCLR TVF that can be used to get this information and others which are persisted in the registry only. For SQL Server 2000, you will have to access the registry keys directly from a batch file or use system databases path (which may be configured during setup to different location).

http://blogs.msdn.com/sqltips/archive/2005/08/19/SqlRegSettings.aspx

Sunday, February 19, 2012

how to filter output based on user's AD group membership?

I want to filter reports based on a users active directory security i.e. what
parameters they can select, what columns they can see
But I can't figure out the best way of doing this and the documentation on
AD seems to assume that the user already understands AD.
From what I can tell I have two options
1) use sql with the openquery syntax - don't think this is going to be an
option due to the hassle here of setting up linked servers (bureaucracy in
the extreme)
2)use system.directoryservices with some code built into to the report - i
don't really understand how to do this, none of the code samples i have seen
seem to do what I want e.g. pass in username from global report parameters
along with the groupname i want to check against, and return whether they are
in that particular group as true/false
help greatly appreciated!
do you know a better way of doing this? code samples? etc
thanks!AD queries in SQL Server using the ADSI can be a problem... I am told it will
only search the first 1000 rows returned by the AD..
if you are using SQL 2005... Take a look at the sys.login_token
It shows all of the AD groups the user is a member of.
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC
I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.
"adolf garlic" wrote:
> I want to filter reports based on a users active directory security i.e. what
> parameters they can select, what columns they can see
> But I can't figure out the best way of doing this and the documentation on
> AD seems to assume that the user already understands AD.
> From what I can tell I have two options
> 1) use sql with the openquery syntax - don't think this is going to be an
> option due to the hassle here of setting up linked servers (bureaucracy in
> the extreme)
> 2)use system.directoryservices with some code built into to the report - i
> don't really understand how to do this, none of the code samples i have seen
> seem to do what I want e.g. pass in username from global report parameters
> along with the groupname i want to check against, and return whether they are
> in that particular group as true/false
> help greatly appreciated!
> do you know a better way of doing this? code samples? etc
> thanks!