Wednesday, February 28, 2007

30:38 - 7th & Arch to 6th & Wharton loop (3.4 miles)

I've slacked off for about a week. Very bad. But it was a really good run, a little slower than usual. I feel motivated to go out again.

I finally got around to getting a RoadID (www.RoadID.com) that displays my insurance information and Sonia's phone number.

Mileage figure from http://www.gmap-pedometer.com.

Thursday, February 22, 2007

28:18 - 7th & Arch to 17th & Lombard (3 miles)

A nice, fast run. I had taken two days off, which does not quite fit with my plan, but I had been feeling pretty beat up. Maybe I need to take three days off a week for now. It occurred to me that even though we live in one of the largest cities in the US, our lives play out in a quadrangle bounded by Washington Ave, Water Street, Vine, and 21st Street. Daniel goes to school out by the Art Museum. Other than that, we pretty much stay in here. That's kind of nice. I listened to the sounds of Philadelphia as I ran back; the saxophonist, the homeless guys asking for money, people speaking Chinese and German... I was in love with the sounds of my city. When I passed through the tunnel by Reading Market and Fillmore, a trucker blew his horn at an indecisive motorist and left me deaf for a few minutes. The bad with the good, I guess.

Wednesday, February 21, 2007

SQL Server: How to move a database file

I recently had to move the log file of a SQL Server database. Initially I thought it might be a simple alter database command, as in How to Change a Database File, but that does not work out:


-- Note: this will not work
alter database MyDatabase
modify file (name='MyDatabase_Log',
filename='c:\Program Files\Microsoft SQL Server\MSSQL\Data_log\MyDatabase_Log.LDF')
go
Msg 5037, Level 16, State 1, Server MYSERVER, Line 1
MODIFY FILE failed. Do not specify physical name.

I found the answer in the SQL Server 2000 Administrator's Pocket Consultant: you have to detach the database, move the file using Windows, and then reattach the database, specifying where the files have gone:


-- Put the database in single user mode
use master
exec sp_dboption MyDatabase, 'single user', true
go

-- Find out where the database files are located
exec sp_helpdb MyDatabase
...
C:\Program Files\Microsoft SQL Server\MSSQL\data\MyDatabase_Data.MDF
C:\Program Files\Microsoft SQL Server\MSSQL\data\MyDatabase_Log.LDF

-- Detach the database
exec sp_detach_db 'MyDatabase', 'true'
go

-- After this, you will need to move the files to their new locations using Windows

-- Reattach the database, specifying where the files are now located
exec sp_attach_db 'MyDatabase',
'C:\Program Files\Microsoft SQL Server\MSSQL\data\MyDatabase_Data.MDF',
'C:\Program Files\Microsoft SQL Server\MSSQL\data_log\MyDatabase_Log.LDF'
go

Tuesday, February 20, 2007

Mardi Gras 2007

Mardi Gras kind of snuck up on me this year. Obviously, it was a much bigger deal when we lived in New Orleans. It's a day off there in most jobs, and Sonia and I would walk down Bourbon Street and catch beads. It was always a real scene. Every year, a group of fundamentalists set up right in the middle of Bourbon Street with banners ("get born again-- ask me how..." etc); the last time we were there, we walked past just as a group of revellers rolled up a shopping cart with a blanket over it. They formed a circle around the fundamentalists, then pulled the blanket off of the shopping cart to reveal a paper mache cow painted gold. Then the revellers got on their knees and started to worship the calf. The funny thing is that the fundamentalists just seemed kind of amused. New Orleans is different. This morning as we got ready for work, Dan was watching PBS kids. There was a show about New Orleans. It had a little footage of previous years' Mardi Gras parades, but mostly it showed how people were reconstructing their lives almost two years after Katrina. And that kind of made me a little sad. When I first moved to New Orleans, if I told someone where I was from, they would say, "wooh wooh, Mardi Gras, party, etc etc". Now they pretty much always give the 25 degree head tilt and say, "Ohh...". I wonder how long it will take for that to stop happening.

Monday, February 19, 2007

30:24 - South Philly

A nice fast run down South to Front Street, down to Washington Ave until Moyamensig Ave-- http://www.gmap-pedometer.com/ measures that to be 3.4 Miles.

Sunday, February 18, 2007

33:24 Around South Philly with Dan

I ran with Dan in the Baby jogger down to Water St. and back up. Nothing special, just a pretty nice run in the snow with my kid.

Saturday, February 17, 2007

49:22 To Dan's school with Dan

The snow made it a little hard to run with the baby jogger, but I took Daniel almost all the way to his school. It took about 25 minutes to get there.

Friday, February 16, 2007

SQL Server: Which databases are set to auto close?

When you import a MSDE version of a database to regular SQL Server, it imports the "Auto Close" property. This is useless in regular SQL Server-- Auto Close is a property used to close down the database when the last connection is closed. This is needless overhead in the Server version of SQL server.

This VBScript script polls all the databases in a SQL Server instance to see their Auto Close property. This script could be modified to show other properties as well, of course.




' Drop this in a text file called show_dbs_with_autoclose.vbs,
' modify the server name to your server name,
' save it, then double click it, and you will get a message box for each
' database set to Auto Close
Dim svr 'As New SQLDMO.SQLServer
Dim db 'As SQLDMO.Database
Set svr = CreateObject("SQLDmo.SqlServer")
svr.LoginSecure = True
svr.Connect "MySQLServer"
For Each db In svr.Databases
If db.DBOption.AutoClose Then
WScript.echo db.Name & " is set to autoclose"
End If
Next


The commented code is there to show how you would use this in VBA or Visual Basic-- this is nice, because then you get all the IntelliSense. Make sure to open references and add in SQLDMO Objects if you do this (of course, in VBScript, this is unnecessary (and impossible)).

SQL Server: How to change a database file name

Note: this is how to change the logical file name of a database file. To change the physical location of a database file, see How to Move a Database File.

I've had a couple of databases hanging around that have very bad logical file names. They were supposed to be test databases, but grew to be production databases (there is a law about this: there is no such thing as a prototype...)

I found a simple piece of code for how to change the names of these logical files:


alter database MyDatabase modify file (name='test', newname='MyDatabase')
alter database MyDatabase modify file (name='test_log', newname='MyDatabase_log')

This allows me to follow my naming convention and neot have to explain to the next guy why my database has logical file names that are animal names.

31:22 Old City/South Philly

A pretty standard run-- I just ran through Independence Mall down 4th to Washington Ave and back up 7th to Arch. I'm just pleased I'm managing to stick to my running schedule, more or less. I'll probably try to mix it up this next week-- different lengths of run, not all just 30 minute chunks.

Thursday, February 15, 2007

30:05 Wash West past Rittenhouse Square

A slippery run in the snow. Feeling good so far, managing to stick to my schedule pretty well. Daniel was sick, so I didn't take him with me. A shame.

Wednesday, February 14, 2007

SQL Server: How to display your session id

Sometimes it's useful to know your session id when you're working from Query Analyzer or oSQL. Then you can tell if you're blocking or being blocked, etc. Here is the code for finding that out-- in this example, I'm running this from oSQL:


C:\>osql -S MyServer -E
1> select @@spid
2> go

------
53

UPDATE: Also, there is a simple way to check this in SQL Query Analyzer: In the status bar at the bottom are listed the user name and session number in parentheses.

Tuesday, February 13, 2007

32:02 - Through Chinatown in the snow

It's starting to snow pretty heavily today-- I went out and ran, which was fun. I'm trying to get my running program going again, so I'm please that I've hit two days in a row. I did right at 3.5 miles, according to my footpod. The good news is that I didn't try to go out further-- I normally end up overshooting my goals and getting injured when I start running again.

Monday, February 12, 2007

SQL Server: How to shrink transaction logs

This is just a sequence that I forget sometimes-- every now and then I get a transaction log that is bigger than I want it to be. This shrinks it pretty well. One thing to be cautious about: make a full backup of the database after you do this.




use MyDatabase
go
checkpoint
go
backup log MyDatabase with truncate_only
go
dbcc shrinkdatabase(MyDatabase)
go
dbcc shrinkfile(MyDatabase_Log)


Now, make a complete backup of the database.




23:20 - Vine Street / Vurt by Jeff Noon

It's been a while since I wrote up a run, though I've been running pretty regularly. I think I'll be gearing up my running time again, as my yoga practice has come to a standstill.

I listened to an audio recording of Vurt, by Jeff Noon. It has to be the best audio book I've ever heard. It tells the story of a group of Manchester kids who are hooked on Vurt feathers, a drug that lets the user experience virtual reality as a dream (the mechanism is never made really clear, which adds to the intrigue). I picked up this recording in Denver well over ten years ago, and I never get tired of it. It ranks right up there with Hitchhiker's Guide to the Galaxy.

Saturday, February 10, 2007

VBScript/VB: How to write error messages to the Event Viewer

I work in a small IT shop where I do all of the internal programming, but also pitch in on help desk duties. Users often call because they got an error message, but cancelled it immediately without reading it.

I've often thought that it would be a good idea to write an entry to a log with any error message text that a program displays, so that a tech can read the error log when a user has cancelled the error message away.

I write a lot of VBScripts and VBA code. In Windows, there is a mechanism for putting messages directly in the event viewer log:




Set WshShell = CreateObject("WScript.Shell")
WshShell.LogEvent 1, "Error 972: Could not invert A-Frame"
WshShell.LogEvent 4, "Information Message: Everything went fine."


This has now become a standard part of my standard error-handler block in VB:




eh:
dim WshError
Set WshError= CreateObject("WScript.Shell")
WshError.LogEvent 1, "Error " & err.number & ": " & err.description


I'm going to start adding this for all of my programs whenever I display messages to my users. What I think would be cool would be if they API for displaying message boxes would include a "WRITE TO EVENT VIEWER" parameter as well.

Tuesday, February 6, 2007

VBScript: how to run a program from vbscript

I always need this one: how do you run a program from within VBScript? For example, you may need to launch notepad or wget from a VBScript. Here is the code to launch notepad:


sub shell(cmd)
' Run a command as if you were running from the command line
dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(cmd)
Set objShell = Nothing
end sub

shell "notepad"

Put that in a text file called "run_notepad.vbs", doubleclick it, and notepad will run. This may not seem too useful, but imagine that you use VBScript to run a series of WGETs, for example, based on input from SQL Server.


UPDATE

I have had a lot of requests for enhancements to this program. The following is the cadillac version. It calls an EXE and asks the user for parameters to pass to the EXE.

 
sub shell(cmd)
' Run a command as if you were running from the command line
dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(cmd)
Set objShell = Nothing
end sub

dim file_name
' Ask the user for a parameter
file_name = inputbox("What file to see?", "File name?", "c:\boot.ini")
if file_name <> "" then
' The user gave the parameter. Open the program
' with the value the user gave.
shell "C:\WINNT\system32\notepad.exe " & file_name
else
msgbox "User cancelled.", 16, "User cancelled"
end if

Monday, February 5, 2007

888-226-3713 - Blue Green Resorts (Be careful)

I get a call from the same number on my cell phone every day: 888-226-3713. When I answer the call, the caller hangs up immediately.

I finally decided to call the number back from my work phone. A recorded announcement thanked me for calling back, and said that the call was from Bluegreen Resorts. The recording pitched some 3 day trip to Vegas.

I thought this sounded fishy, so I Googled "bluegreen resorts", and about the 3rd link was for The Ripoff Report.

I have no direct experience with Bluegreen Resorts, but I would say that in the very least, you should proceed with caution if you deal with them.

(Note: that number was 8882263713, Bluegreen resorts.)