May 2011 Entries

Ten minutes ago I created a scratch db instance with a name I mistyped. Not good!   Fortunately, I have admin privileges so I can change it in my lab environment.  If you're an admin AND no other users are accessing the DB instance, here's what you can do:

USE master
go
EXEC sp_renamedb 'MetroWrongName', 'MetroRightName'
GO

If someone is using the instance, there is a workaround. Do this:

 

USE master
go

-- flag the instance for single user only

EXEC sp_dboption 'MetroWrongName','Single User', True
GO

-- make the name change with the rename sproc
EXEC sp_renamedb 'MetroWrongName', 'MetroRightName'
GO

-- flag the newly named instance back to mulitusers

EXEC sp_dboption 'MetroRightName','Single User', False
GO

The worst part about web application development is the phase in the unit testing where we developers swear we've fixed something,  but still when we test the change, the fix isn't there. After awhile, we remember to clear the browser cache and we discover the fix worked!  In some cases, we really haven't fixed what we thought we fixed--and in other cases, we haven't really cleared the cache. 

I was working in FireFox recently and realized I hadn't really cleared the cache when I added a new button on a form that didn't show. I decided at that point, that I must not have truly cleared out the cache. To confirm my theory, I downloaded Google Chrome and ran the web app again. There was my new button! This sent me on a quest to clear the cache in in FireFox.

After some fiddling with FireFox, here are the steps I used to clear the cache:

   1. Opened up the FireFox browser
   2. Typed about:config in the address bar
   3. Typed ‘cache’ in the search bar, and looked for: network.http.use-cache.
   4. Double clicked  network.http.use-cache in order to set it to false. (BTW, Double clicking it again will set it to true and re-enable the cache)


This should finally eliminate old files while your testing.


Tip: If you don't want to turn of the cache in FF to forcibly reload a page and all its dependencies, direct from source, ignoring local and proxy caches-- hold the shift key and hit reload.

 

 

 The easiest way in MS SQL 2005 and up is to use the SQL Management Studio,  go to Views, highlight the name of the view you are interested in, right click, select Script View  as/Create to/Clipboard.

 

open up notepad or your prefered editor and paste the contents of your clipboard. The SQL used to create the view should show up in your editor.

If this doesn't work, or if you are working with older  versions of SQL Server, look at the system objects as follows:

use [YouDatabseInstanceName]
go

select * from sys.objects
where type = 'V'
and name = 'YourViewName'

-- capture the object id and schema_id to examine later
-- object_id = 436921992
-- schema_id = 1

-- this should show you whether or not there is anything set in the definition coloumn

select * from sys.sql_modules
where object_id = 436921992


-- use to examine which schema name the view is in


select * from sys.schemas
where schema_id = 1

 

-- Use this to capture all the views by the schema name


select o.name
      ,o.object_id
  into #views
  from sys.objects o
  join sys.schemas s
    on s.schema_id = o.schema_id
 where o.type in  ('V')
   and s.name = 'dbo'

select * from #views

-- use this to examine the definition of all views

select definition + char(10) + 'go' + char(10)
  from sys.sql_modules c
  join sys.objects o
    on c.object_id = o.object_id
  join #views o2
    on o.object_id = o2.object_id