A trace amount of water is typically unavoidable as an impurity in ionic liquids, which is a huge challenge for their application in Mg-ion batteries. Here, we employed molecular sieves of different pore diameters (3, 4, and 5 Å), to effectively remove the trace amounts of water from 1-methyl-1-propylpiperidinium bis(trifluoromethylsulfonyl)imide (MPPip-TFSI) and 1-butyl-1-methylpyrrolidinium bis(trifluoromethylsulfonyl)imide (BMP-TFSI). Notably, after sieving (water content <1 mg ⋅ L$^{−1}$), new anodic peaks arise that are attributed to the formation of different anion-cation structures induced by minimizing the influence of hydrogen bonds. Furthermore, electrochemical impedance spectroscopy (EIS) reveals that the electrolyte resistance decreases by ∼10 % for MPPip-TFSI and by ∼28 % for BMP-TFSI after sieving. The electrochemical Mg deposition/dissolution is investigated in MPPip-TFSI/tetraglyme (1 : 1)+100 mM Mg(TFSI)$_2$+10 mM Mg(BH$_4$)$_2$ using Ag/AgCl and Mg reference electrodes. The presence of a trace amount of water leads to a considerable shift of 0.9 V vs. Mg$^{2+}$/Mg in the overpotential of Mg deposition. In contrast, drying of MPPip-TFSI enhances the reversibility of Mg deposition/dissolution and suppresses the passivation of the Mg electrode.