I'm working with Visual Studio Testing Tools, and I'd like to write some database tests. Therefor I added a Data\Test.mdf
file to my solution, and added a DeploymentItemAttribute
to my test:
[DeploymentItem("\\Data\\Test.mdf")]
The test project has a Connection String Setting to, which looks like this:
Data Source=.\SQLEXPRESS;AttachDbFilename=.\Test.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True
The file is deployed to the test output directory. It's not found, however. SQL Server uses a different root directory. I'm struggling to find it. I cannot change it at runtime, since an ASP.NET membership provider is involved.
I get the following SqlException
on SqlConnection.Open
:
An attempt to attach an auto-named database for file .\Test.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.