your sqlcmd is out of scope, once you closed the } all the information about the sqlcmd is dumped and no reference to it exists