Question

I have a database project in my solution and the requirement is simple (not so sure about the implementation).

Is there a way to deploy the database project programatically?

PS: I don't mean attach an MDF file. I mean deploy the database to a SQL Server instance.

Was it helpful?

Solution

You can add the script for create the database as an "Embedded Resource" then execute it when needed with the standard ExecuteNonQuery(...). But you probably need to upgrade it in the future so the idea is, a part the first drop, have some table somewhere keeping the schema version, then have multiple embedded resource contatining script to jump to one version to the next one. When the service start check the version against the expected one, if not the same launch the needed script(s) to reach the current version.

OTHER TIPS

Create the database SQL however you like and include it in your project. Then simply execute the SQL script against the server.

I use this when I include SQLite databases in my project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top