Do not use sp_attach_db(). As MSDN states it may be removed in the future.
Use CREATE DATABASE .... FOR ATTACH
CREATE DATABASE [C:\xyz.MDF] ON
( FILENAME = N'C:\xyz.mdf' ),
( FILENAME = N'C:\xyz_log.LDF' )
FOR ATTACH
If you're using SSMS, before hitting the 'OK' button, check for the Script button on top. Click it & it'll show you the underlying script for the action. You can learn from it.