下面的代碼片段是我從SQL事件探查器中提取的。我修改了一下以刪除不太有用的列。代碼現在返回一行具有以下colums:
- IsFullTextInstalled
- MasterDBLogPath
- MasterDBPath
- ErrorLogPath
- RootDirectory
- IsCaseSensitive
- MaxPrecision
- VERSIONSTRING(例如10.50。 2500.0)
- 版本(例如開發版(64位))
- ProductLevel(例如SP1)
- IsSingleUser
- EngineEdition(例如3)
- 歸類(例如Latin1_General_CI_AS)
- IsClustered
- NETNAME(如主機名)
- BuildClrVersionString(如V2.0.50727)
好運。
declare @RegPathParams sysname
declare @Arg sysname
declare @Param sysname
declare @MasterPath nvarchar(512)
declare @LogPath nvarchar(512)
declare @ErrorLogPath nvarchar(512)
declare @n int
select @n=0
select @RegPathParams=N'Software\Microsoft\MSSQLServer\MSSQLServer'+'\Parameters'
select @Param='dummy'
while(not @Param is null)
begin
select @Param=null
select @Arg='SqlArg'+convert(nvarchar,@n)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', @RegPathParams, @Arg, @Param OUTPUT
if(@Param like '-d%')
begin
select @Param=substring(@Param, 3, 255)
select @MasterPath=substring(@Param, 1, len(@Param) - charindex('\', reverse(@Param)))
end
else if(@Param like '-l%')
begin
select @Param=substring(@Param, 3, 255)
select @LogPath=substring(@Param, 1, len(@Param) - charindex('\', reverse(@Param)))
end
else if(@Param like '-e%')
begin
select @Param=substring(@Param, 3, 255)
select @ErrorLogPath=substring(@Param, 1, len(@Param) - charindex('\', reverse(@Param)))
end
select @[email protected]+1
end
declare @SmoRoot nvarchar(512)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\Setup', N'SQLPath', @SmoRoot OUTPUT
SELECT CAST(FULLTEXTSERVICEPROPERTY('IsFullTextInstalled') AS bit) AS [IsFullTextInstalled], @LogPath AS [MasterDBLogPath], @MasterPath AS [MasterDBPath], @ErrorLogPath AS [ErrorLogPath], @SmoRoot AS [RootDirectory], CAST(case when 'a' <> 'A' then 1 else 0 end AS bit) AS [IsCaseSensitive], @@MAX_PRECISION AS [MaxPrecision], SERVERPROPERTY(N'ProductVersion') AS [VersionString], CAST(SERVERPROPERTY(N'Edition') AS sysname) AS [Edition], CAST(SERVERPROPERTY(N'ProductLevel') AS sysname) AS [ProductLevel], CAST(SERVERPROPERTY('IsSingleUser') AS bit) AS [IsSingleUser], CAST(SERVERPROPERTY('EngineEdition') AS int) AS [EngineEdition], convert(sysname, serverproperty(N'collation')) AS [Collation], CAST(SERVERPROPERTY('IsClustered') AS bit) AS [IsClustered], CAST(SERVERPROPERTY(N'MachineName') AS sysname) AS [NetName], SERVERPROPERTY(N'BuildClrVersion') AS [BuildClrVersionString]
但是您使用哪個條目?在我的情況下,我的主/ msdb/model數據庫位於與我的用戶數據庫不同的目錄中.....「 – 2010-01-06 17:25:46
」與其他數據庫一致「是我從問題中解脫出來的。他不一定要問如何找到默認的數據目錄,因爲marc_s指定了解決方案。真的聽起來像2個不同的問題海事組織。在我管理的幾個實例中,出於性能原因,我們必須有多個驅動器來承載不同的數據庫,因此在大多數情況下,這種情況下默認數據目錄是不好的選擇。 – 2010-01-06 21:37:53
對此感到抱歉。這是措辭嚴厲,雖然我真的在默認數據目錄之後,這個答案也是一樣有效,所以我也贊成這一點。謝謝 – Dolbz 2010-01-07 11:24:15