22. Januar 2014 09:34
23. Januar 2014 12:04
23. Januar 2014 12:06
24. Januar 2014 10:23
declare @NAVTables table (idx int identity(0,1),name varchar(200));
declare @i int;
declare @max int;
declare @count int;
declare @tablename varchar(200);
declare @stmt nvarchar(max);
INSERT INTO @NAVTables (name)
SELECT name FROM sys.databases;
SELECT @i = min(idx), @max = max(idx) + 1 FROM @NAVTables;
WHILE(@i < @max)
BEGIN
SELECT @tablename = name FROM @NAVTables WHERE idx = @i;
SET @stmt = N'SELECT @count=COUNT(TABLE_NAME) FROM [' + @tablename + N'].INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''User'';';
exec sp_executesql @stmt,N'@count int output',@count output;
IF @count = 0 BEGIN
DELETE FROM @NAVTables WHERE idx = @i;
END;
SELECT @i = @i + 1;
END;
SELECT * FROM @NAVTables;
declare @NAVTables table (idx int identity(0,1),name varchar(200));
declare @i int;
declare @max int;
declare @count int;
declare @tablename varchar(200);
declare @stmt nvarchar(max);
INSERT INTO @NAVTables (name)
SELECT name FROM sys.databases;
SELECT @i = min(idx), @max = max(idx) + 1 FROM @NAVTables;
WHILE(@i < @max)
BEGIN
SELECT @tablename = name FROM @NAVTables WHERE idx = @i;
SET @stmt = N'SELECT @count=COUNT(TABLE_NAME) FROM [' + @tablename + N'].INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''User'';';
exec sp_executesql @stmt,N'@count int output',@count output;
IF @count = 0 BEGIN
DELETE FROM @NAVTables WHERE idx = @i;
END
ELSE
BEGIN
SET @stmt = N'SELECT @count=COUNT([User ID]) FROM [' + @tablename + N'].[dbo].[User] WHERE [User ID] = ''SUPER'';';
exec sp_executesql @stmt,N'@count int output',@count output;
IF @count = 0 BEGIN
DELETE FROM @NAVTables WHERE idx = @i;
END;
END;
SELECT @i = @i + 1;
END;
SELECT * FROM @NAVTables;
30. Januar 2014 18:14
' Windows Script Host Runtime Library
Option Explicit
Dim wshshell,shell
Dim strComputer
Dim objMasterConnection
dim objDatabaseList
Dim objDataConnection1,objDataConnection2
dim objDataInfo1,objDataInfo2
Dim Zaehler
dim SQLBefehl1,SQLBefehl2
dim NavDatabasesName(200)
dim NavDatabasesCount
dim Schleife
dim SchleifenName
dim Lizenz
dim Lizenzname
dim strProcessName
dim objWMIService
dim colProcessList
dim objProcess
dim PID
on error resume next
strComputer = "NAME DES SQL SERVERS"
Set wshshell = CreateObject("WScript.Shell")
set shell = WScript.CreateObject("Shell.Application")
NavDatabasesCount = 0
Set objMasterConnection = CreateObject("ADODB.Connection")
objMasterConnection.Open _
"Provider=SQLOLEDB;Data Source=" & strComputer & ";" & _
"Trusted_Connection=Yes;Initial Catalog=Master"
Set objDatabaseList = objMasterConnection.Execute("Select Name From SysDatabases order by name")
Set objDataConnection1 = CreateObject("ADODB.Connection")
Set objDataConnection2 = CreateObject("ADODB.Connection")
If objDatabaseList.Recordcount = 0 Then
Wscript.Echo "No databases could be found."
Else
Do Until objDatabaseList.EOF
objDataConnection1.Open _
"Provider=SQLOLEDB;Data Source=" & strComputer & ";" & _
"Trusted_Connection=Yes;Initial Catalog="& objDatabaseList.Fields("Name")
Zaehler = 0
SQLBefehl1 = "SELECT count(*) FROM ["& objDatabaseList.Fields("Name") &"].[dbo].[User] where ""User ID"" = 'SUPER'"
set objDataInfo1 = objDataConnection1.Execute(SQLBefehl1 )
if err.number = 0 then
Zaehler = Zaehler + objDataInfo1(0).value
end if
err.clear
objDataConnection1.close
objDataConnection2.Open _
"Provider=SQLOLEDB;Data Source=" & strComputer & ";" & _
"Trusted_Connection=Yes;Initial Catalog="& objDatabaseList.Fields("Name")
SQLBefehl2 = "SELECT count(*) FROM ["& objDatabaseList.Fields("Name") &"].[dbo].[Benutzer] where ""Benutzer ID"" = 'SUPER'"
set objDataInfo2 = objDataConnection2.Execute(SQLBefehl2 )
if err.number = 0 then
Zaehler = Zaehler + objDataInfo2(0).value
end if
err.clear
objDataConnection2.close
if zaehler <> 0 then
NavDatabasesCount = NavDatabasesCount + 1
NavDatabasesName(NavDatabasesCount) = objDatabaseList.Fields("Name")
end if
objDatabaseList.MoveNext
Loop
End If
objMasterConnection.close
for Schleife = 1 to NavDatabasesCount
SchleifenName = NavDatabasesName(Schleife)
{meine eigene WSH Verarbeitung}
next
31. Januar 2014 10:12
h-d.neuenfeldt hat geschrieben:Die Lösung von DANJO griff bei mir nicht, da auf dem SQL-Server noch andere Datenbanken vorgehalten werden, die eine Tabelle USER bzw BENUTZER haben und keine Navisondatenbanken sind ..
declare @NAVTables table (idx int identity(0,1),name varchar(200));
declare @i int;
declare @max int;
declare @count int;
declare @tablename varchar(200);
declare @stmt nvarchar(max);
INSERT INTO @NAVTables (name)
SELECT name FROM sys.databases;
SELECT @i = min(idx), @max = max(idx) + 1 FROM @NAVTables;
WHILE(@i < @max)
BEGIN
SELECT @tablename = name FROM @NAVTables WHERE idx = @i;
SET @stmt = N'SELECT @count=COUNT(TABLE_NAME) FROM [' + @tablename + N'].INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''$ndo$dbproperty'';';
exec sp_executesql @stmt,N'@count int output',@count output;
IF @count = 0 BEGIN
DELETE FROM @NAVTables WHERE idx = @i;
END;
SELECT @i = @i + 1;
END;
SELECT * FROM @NAVTables;