views:

27

answers:

1

I have a database project and a setup project in my Visual Studio 2010 solution. What's the simplest way to have this database created by the setup project? I was hoping it would be simple enough to just add the database project output to the setup package and that would magically work, but it doesn't look like it's that simple.

Let me know if you need any more info. Thanks!

A: 

You can create a script to attach the database.

From http://technet.microsoft.com/en-us/library/ms187858.aspx

USE master;
GO
CREATE DATABASE MyDatabase
    ON (FILENAME = 'C:\MyDatabase.mdf'),
    (FILENAME = 'C:\MyDatabase.ldf')
    FOR ATTACH;
GO

You just need to establish a connection with Sql Server, make sure the files are in the correct spot, and then execute the sql.

Brian

related questions