My code is working in preview, but no working when published.

On the left side in your Wix-Editor, you will see …

…there you can choose the right database.
On the right side on the very bottom of this pic, you can see […] 3-points (a sign for a menu). Click on it and take a look onto the options.