Why does während take genitive in the first example and dative in the second?
Was hast du während der Ferien gemacht?
Während dem Vortrag schlief er ein.
German Language Stack Exchange is a bilingual question and answer site for speakers of all levels who want to share and increase their knowledge of the German language. It's 100% free, no registration required.Sign up to join this community
The difference between use of dative and use of genitive is not semantic. Both forms mean the same.
Generally, genitive is used with während. There are some cases, directed by syntax, where dative is used. These cases are not specific for während, but apply to genitive in general. These cases include the case of a singular noun which has no accompanying word (article, pronoun or adjective) which would make the case clear. For example it would be considered more accepted to say:
Während Urlaub geschlossen.
* Während Urlaubs geschlossen.
If there is an article or adjective indicating the case, genitive is more accepted:
Während langer Krankheit geschlossen.
There are more detailed differentiations, which you can find in this script (in German): Peter Gallmann - Die Genitivregel.
Besides these cases, there is some variance of using genitive or dative.
Use of dative in other cases (not mentioned in the script) is an instance of language change and a matter of debate.
The older genitive form demanded by während is now sometimes replaced by a dative form. Conservative opinions deem use of dative "wrong" here (whatever that is supposed to mean). These opinions include some grammar books fancying a prescriptive approach to grammar.
Nonetheless, a majority of competent speakers of German does use it. Use of während with dative does not only exist in the colloquial register of speech, but can also be found in newspapers. (Examples can be found, for instance, in the corpus search of DWDS.)
Thanks to David Vogt for making me aware of the DWDS corpus search.
Use of dative or genitive can be used as a means of social distinction, both by speakers and listeners. The style difference is aligned with the social group differences: Genitive might be described as "posh", or even "uppity" by some, while dative might be described as "colloquial", "uneducated", "lower class" or even "stupid" by others.
Note that während is not the only instance of this change from mandatory genitive to optional genitive or dative. Another example is wegen. The following joke illustrates the social difference quite well:
Was ist der Unterschied zwischen einem Comedian und einem Kabarettisten? -- Der Comedian macht es wegen dem Geld. Und der Kabarettist macht es wegen des Geldes.
The point of the joke is lost in translation:
What is the difference between a standup comedian and a cabaret artist? The standup comedian does it for the money. And the cabaret artist does it for the money (but in a grammatically different way).
Whether während is used with genitive or dative, has undergone some changes in German before. Following the example of the French preposition pendant ("pending", but also: "meanwhile") which has been formed from pendre ("to depend", "to hang"), während stems from the verb währen ("to last", "to endure", "to continue"), in its participle form, währendes or währender.
This participle has been split into the conjunction während and an article, leading to a genitiv interpretation. However, early uses of während with dative, i.e. already in the 19th century are to be encountered. For instance während with dative can be found in texts of Goethe, Lessing and Herder, here for instance in the play Emilia Galotti by Lessing:
während dem handgemenge soll mein bedienter Emilien ergreifen, als ob er sie retten wolle.
So, während has been used with genitive and dative forms basically from the beginning.
The popular dictionaries that are quoted most around here, namely Duden, DWDS, Wiktionary all mark the use of während with dative as colloquial, and say that it is used with genitive in standard German.
Duden Grammatik, as @jonathan.scholbach mentions in the comments, deems the use with dative possible, "especially in spoken language".
Langenscheidt EN-DE even only mentions the use with dative.
It's definitely popular nowadays to use "während" with dative, but the use with genitive is probably the safe way if you use it in formal language as a German learner, e.g. in a test.