Posts

The SQL Server Service Broker for the current database is not enabled

The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported. Please enable the Service Broker for this database if you wish to use notifications. ----Check if the service broker is enabled SELECT is_broker_enabled FROM sys.databases WHERE name = 'YOUR_DB' -- Enable broker ALTER DATABASE YOUR_DB SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE -- If fail above then new broker ALTER DATABASE YOUR_DB SET NEW_BROKER WITH ROLLBACK IMMEDIATE

SQL Server 2005: List all databases

List all the databases on SQL Server: ----SQL SERVER 2005 System Procedures EXEC sp_databases EXEC sp_helpdb ----SQL 2000 Method still works in SQL Server 2005 SELECT name FROM sys.databases SELECT name FROM sys.sysdatabases ----SQL SERVER Un-Documented Procedure EXEC sp_msForEachDB 'PRINT ''?'''

Service Unavailable of IIS

Today after installed some Windows patches to the server and reboot, one of a website does not work. It shows "Service Unavailable" when browse it. I try to restart the website but problem still exist. Finally found that the Application Pools cannot start properly because of the AD account used have changed the password.

SQL: Insert custom value into IDENTITY column

SET IDENTITY_INSERT clienttable ON insert into EmployeeTable ... SET IDENTITY_INSERT clienttable OFF

C#: Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type.

Today I got "Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type." error in the C# application. After my trace, it is caused by this line: DateTime? moveOutDate = dt.Rows[0].Field ("MoveOutDate"); You should make it as: DateTime? moveOutDate = dt.Rows[0].Field ("MoveOutDate");

Clear SQL Server Cache

When perform benchmark testing, make sure you need to clean the SQL server cache in order to have a more accurate result. -- Clean all data in the cache DBCC DROPCLEANBUFFERS -- clean cache from stored procedure DBCC FREEPROCCACHE

Display the size of all tables in SQL Server 2005

SET NOCOUNT ON DBCC UPDATEUSAGE(0) -- DB size. EXEC sp_spaceused -- Table row counts and sizes. CREATE TABLE #t ( [name] NVARCHAR(128), [rows] CHAR(11), reserved VARCHAR(18), data VARCHAR(18), index_size VARCHAR(18), unused VARCHAR(18) ) INSERT #t EXEC sp_msForEachTable 'EXEC sp_spaceused ''?''' SELECT * FROM #t -- # of rows. SELECT SUM(CAST([rows] AS int)) AS [rows] FROM #t DROP TABLE #t