Effect of solvent in the reaction of alkyl halide with nitrite ion
Let me first clear out the difference between reaction of alkyl halide with $\ce{AgNO2}$ and $\ce{NaNO2/KNO2}$

The synthesis of nitro compounds from reaction of alkyl halides with alkali metal nitrites using DMSO/DMF as medium is known as the Victor meyer reation($\ce{AgNO2}$) or Kornblum reaction($\ce{NaNO2/KNO2}$). The products of these reaction are generally mixture of nitroalkanes and alkyl nitrites. But the main difference between them is that the % yield of nitroalkane is higher on reaction with $\ce{AgNO2}$ than that of $\ce{NaNO2/KNO2}$.Whereas % yield of alkyl nitrite is higher on reaction with $\ce{NaNO2/KNO2}$ than that of $\ce{AgNO2}$. The required mechanisms for the reactions are..



Now as for the reaction of $\ce{NaNO2/KNO2}$ with alcohol, there is no involvement of alkyl halide. Alkyl nitrite can also be prepared by adding concentrated $\ce{H2SO4}$ to the aqueous solution of $\ce{NaNO2/KNO2}$ and alcohol. The mechanism of this reaction is



Source books:


The Nitro Group in Organic Synthesis By Noboru Ono
Organic Chemistry of Explosives By Jai Prakash Agrawal, Robert Hodgson
Sourcebook of Advanced Organic Laboratory Preparations By Stanley R. Sandler, Wolf Karo