If you want to deploy a database as MDF along with your setup, there’s a big problem you will get with: where you copy the files so that SQL Server is able to read/write them ?

One method is to copy them in SQL Server’s data folder, something like C:\Program Files\Microsoft SQL Server\MSSQL\Data. However, under Vista that folder is a protected area and, nevermind that, it’s not very nice to copy files in SQL Server’s folders.

The best method is thus to copy the MDF to your program’s folder and then give read/write rights to the user SQL Server is running under. You can use EnumServicesStatus to find the SQL Server service, then QueryServiceConfig to find the user account and then the AddAccessRights from here to set the actual permissions.