  We propose a method of constructing a gauge invariant canonical formulation
for non-gauge classical theory which depends on a set of parameters.
Requirement of closure for algebra of operators generating quantum gauge
transformations leads to restrictions on parameters of the theory. This
approach is then applied to bosonic string theory coupled to massive background
fields. It is shown that within the proposed canonical formulation the correct
linear equations of motion for background fields arise.
