I'm creating my first ASP.NET, EF code first web app.
The problem I have is in deploying and running it on a local IIS machine that is remote to the SQL Server Express ( SYSDEVSERVER
).
I'm unable to formulate a connection string that creates the EF DB in the App_Data
folder of the web app. Instead, the remote DB server, create a DB local to itself.
The connection string that works (so far) is as follows:
<add name="MyWebApp"
connectionString="Data Source=SYSDEVSERVER\SQLEXPRESS; user id=USER;password=PASSWORD; Initial Catalog=MyDB; Trusted_Connection=no;"
providerName="System.Data.SqlClient" />
OK, so I'm not specifying an AttachDbFileName
to say that the DB is in the App_Data
folder of the web app - that's why the DB is created on the server.
If I do specify AttachDbFilename
like this:
AttachDbFilename=|DataDirectory|\MyDB.mdf
I get an error message
Invalid value for key 'attachdbfilename'
So far, I've been unable to resolve this, so for now I'll have to accept the DB residing local to the remote server, but I'm not too happy about it.
Does anyone know what connection string to use that allows the database to be created in the App_Data
folder?
Thanks
For local DB a conection string in this format should work
<add name="MyWebApp"
connectionString="Data Source=(localdb)\v11.0;AttachDbFilename=|DataDirectory|\MyDB.mdf;Initial Catalog=MyDB;Integrated Security=True;"
providerName="System.Data.SqlClient" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.