Hi,
I have created a vbscript which will do the following tasks:
1. Create a temporary table
2. Fill the table with the result set from DBCC sqlperf (logspace)
3. Add a column named "freespace" to calculate the available space
4. And to display the "freespace" value only for a particular database.
The SQL statements are giving me the exact result. But while using VBscript, I am receiving an error "Item cannot be found in the collection corresponding to t he requested name or ordinal". I am not getting where exactly I am going wrong. I have shared my script below. Any suggestion will help a lot.
Set objDatabase = CreateObject("ADODB.Connection")
objConnString = "Provider=SQLOLEDB;server=.\INST01;Trusted_Connection=yes;"_
&"Initial Catalog=master;"
objDatabase.open objConnString
objStrSqlStmnts = "set nocount on DECLARE @sql_command varchar(255) IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects "& vbCrLf
objStrSqlStmnts = objStrSqlStmnts &"WHERE ID = OBJECT_ID(N'tempdb..#TempForLogSpace')) DROP TABLE #TempForLogSpace "& vbCrLf
objStrSqlStmnts = objStrSqlStmnts &"CREATE TABLE #TempForLogSpace (DBname varchar(40), LogSize_MB real, LogSpaceUsed_pct real, Status int) "& vbCrLf
objStrSqlStmnts = objStrSqlStmnts &"SELECT @sql_command = 'dbcc sqlperf (logspace)' INSERT #TempForLogSpace EXEC (@sql_command) "& vbCrLf
objStrSqlStmnts = objStrSqlStmnts &"DECLARE @ColName nvarchar(100), @DynamicSQL nvarchar(250), @DynamicSQL1 nvarchar(250) SET @ColName='freespace' "& vbCrLf
objStrSqlStmnts = objStrSqlStmnts &"SET @DynamicSQL = 'ALTER TABLE #TempForLogSpace ADD ['+ CAST(@ColName AS nvarchar(100)) +'] "& vbCrLf
objStrSqlStmnts = objStrSqlStmnts &"nvarchar (100) NULL' EXEC(@DynamicSQL) SET @DynamicSQL1 = 'update #TempForLogSpace set freespace = "& vbCrLf
objStrSqlStmnts = objStrSqlStmnts &"(logsize_MB - ((logsize_MB*LogSpaceUsed_pct)/100)) select freespace = convert(real,freespace) from #TempForLogSpace where "& vbCrLf
objStrSqlStmnts = objStrSqlStmnts &"DBname = ''dbGentran''' EXEC(@DynamicSQL1) set nocount off"
set objReturn = objDatabase.Execute(objStrSqlStmnts)
objResult = objReturn(0).value
msgbox objReturn
I am receiving the error in "objResult = objReturn(0).value" this line.
Crynet