December 19, 2008 at 11:33 am
Need some help...
The following gives an error.
SELECT '--Shows avail free DB space ' as ' '
exec sp_MSForEachDB 'Use ? SELECT name AS ''Name of File'', size/128.0 -CAST(FILEPROPERTY(name, ''SpaceUsed'' )
AS int)/128.0 AS ''Available Space In MB'' FROM .SYSFILES'
I also got this when I tried to execute - EXEC sp_msForEachDB 'PRINT ''?'''
Could not find stored procedure 'sp_msForEachDB'.
We are on SQL Server Enterprise 2005
Any ideas ?
Regards
Gagan
December 19, 2008 at 11:41 am
It worked fine for me on SQL 2008
You have to remove the period and lower case 'sysfiles' (SYSFILES won't work for me)
exec sp_MSForEachDB 'Use ? SELECT name AS ''Name of File'', size/128.0 -CAST(FILEPROPERTY(name, ''SpaceUsed'' )
AS int)/128.0 AS ''Available Space In MB'' FROM sysfiles' --select * from sysfiles
December 19, 2008 at 11:47 am
Rudy,
If this is intended for SQL 2005/2008 why are you using legacy views like sysdatabases and sysfiles in the code. You also are not using the schema qualifiers in the code.
Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
My Blog | Twitter | MVP Profile
Training | Consulting | Become a SQLskills Insider
Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]
December 19, 2008 at 11:51 am
I tried this
SELECT '--Shows avail free DB space ' as ' '
exec sp_MSForEachDB 'Use ? SELECT name AS ''Name of File'', size/128.0 -CAST(FILEPROPERTY(name, ''SpaceUsed'' )
AS int)/128.0 AS ''Available Space In MB'' FROM sysfiles'
Gave me the following output
(1 row(s) affected)
Msg 2812, Level 16, State 62, Line 2
Could not find stored procedure 'sp_MSForEachDB'.
Results was only
--Shows avail free DB space
Is the installation missing the procedure ?
December 19, 2008 at 11:53 am
That was definitley a nice article and the code works. I only had to do minor changes like:
exec sp_MSForEachDB 'Use [?] SELECT name AS ''Name of File'', size/128.0 -CAST(FILEPROPERTY(name, ''SpaceUsed'' )
AS float)/128.0 AS ''Available Space In MB'' FROM sysfiles'
They way you had it wriiten does not support case sensitive collation.
December 19, 2008 at 11:55 am
The output for sp_help sp_MSForEachDB is the following.
Msg 15009, Level 16, State 1, Procedure sp_help, Line 66
The object 'sp_MSForEachDB' does not exist in database 'master' or is invalid for this operation.
December 19, 2008 at 11:58 am
Got it, Thank you !!
December 19, 2008 at 12:07 pm
WOW! Love all the comments and code changes everyone is posting!
Now Mr Kehayias ask a good question
"If this is intended for SQL 2005/2008 why are you using legacy views like sysdatabases and sysfiles in the code. You also are not using the schema qualifiers in the code."
The code was written to quickly get some information. I have a collection of code from other projects, copy/paste some and wrote some to make this new one. So yes, there is older type code but it works so why not use it (for now). I didn't have a lot of time to write the code as we has a production issue to address.
If anyone would like to update the code and post it here, that would be great. But the code "as is" worked just fine and help me to correct the production issue.
Rudy
Rudy
December 19, 2008 at 12:11 pm
As my coworker jbwillia pointed out, it doesn't support case insensitive collation databases like Adventure works, and it also fails for databases like the Sharepoint Admin databases which are installed by default with a GUID in the database name so bracketing the ? as [?] is necessary for those databases. I also don't see that it is dumping some significant items like the memory clerks which could help explain why the system is not responding properly. Just some small feedback items, and certainly not detracting from the article.
We didn't have a set of code for this kind of scenario in place prior to today, but we will after the article since it isn't difficult to put into place. I tend to be motivated out of necessity for creating scripts like this, but this article points out the need.
Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
My Blog | Twitter | MVP Profile
Training | Consulting | Become a SQLskills Insider
Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]
December 19, 2008 at 12:15 pm
Would you be willing to post an updated version of the complete code to correct the issues? As mentioned I don't have much time right now but will look at all the comments and update the code sometime in Feb 2009.
Thanks,
Rudy
Rudy
December 19, 2008 at 1:04 pm
The code has been edited to be one long file.
December 19, 2008 at 1:19 pm
I did, and fixed a minor problem: If your SQL Server is CASE SENSITIVE the original code won't work due some names spelled in CAPITALs. The attached .txt file fixes these little problems.
Great article.
Thanks a lot
December 19, 2008 at 10:56 pm
I found what was wrong with:
"CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st":
I worked in SSMS / SQL Server 2005 connected to a database having "Compatibility level: SQL Server 2000 (80)".
Either connecting to the master database or changing to "Compatibility level: SQL Server 2005 (90)" did the job.
Thanks, Leendert.
December 20, 2008 at 9:19 am
Good stuff guys, I'm going to make this part of our standard server build.
Probably add an exec sp_readerrorlog after the fixed driver proc.
December 21, 2008 at 1:23 am
It is a wonderful article...:)
Viewing 15 posts - 16 through 30 (of 38 total)
You must be logged in to reply to this topic. Login to reply