How can I use a mdf file that should be located in the solution directory (or elsewhere) in combination with Entity Framework? By default EF creates the file in "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA". Additionally it would be nice to be able to access the database over a windows peer-to-peer network after staring the .net application which initializes the server instance.
I guess i have to use a connection string something similar to this: http://msdn.microsoft.com/en-us/library/bb264564%28v=sql.90%29.aspx, which uses User Instance and AttachDbFilename
This post states that i can use connection strings as usual with EF: http://blogs.msdn.com/b/adonet/archive/2012/01/12/ef-4-3-configuration-file-settings.aspx
What i get when using my own (not the default EF) connection string is: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. (Configuration system failed to initialize)
<configuration>
<connectionStrings>
<add name="SomeContext"
providerName="System.Data.SqlClient"
connectionString="Server=.\SQLEXPRESS;
AttachDbFilename=C:\temp\SomeNamespace.SomeContext.mdf;
Integrated Security=True;
User Instance=True" />
</connectionStrings>
...
Versions used:
SQL Server Express Edition R2 SP1
EF 4.3.1 (Code First)