Every car with a motorized sun roof has a manual crank over ride to close it in case there is a motor failure. Check the manual and find out where the tool is and where to insert the tool to close the roof.
First, I would check to make sure there isn't a fuse blown that operates the roof. If that isn't the case, you will have to take it to a repair shop,preferably BMW to let them have a look.
The most likely cause is a crack or short in the sun-roof cable. It can be replaced without a great deal of effort. It does however require removing the entire sunroof cassette to access the cable.
On most all cars equipped with motorized sunroofs there is typically a manual override that will allow you to open or close it manually. I believe this was mandated by NHSTA as a saftey feature. Look in your owners manual for the release to manually open or close the sunroof. It should be in the front of the unit.