Reputation: 8474
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.
Upvotes: 2
Views: 1458
Reputation: 33262
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.
Upvotes: 3
Reputation: 776
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.
Upvotes: 0
Reputation: 13970
You can use plain sql commands to achieve this.
http://msdn.microsoft.com/en-us/library/49b92ztk(v=vs.80).aspx
http://www.codeproject.com/Articles/16231/Deploy-your-Application-and-Database
Best regards
Upvotes: 3