Last post May 09, 2017 04:17 PM by PatriceSc
May 09, 2017 06:37 AM|ngaisteve1|LINK
Hi, I try my first azure deployment. It is just a sample project.
But, it shows this error:
Web deployment task failed. (Cannot attach the file 'C:\Users\User\Desktop\WebApplication1\WebApplication1\App_Data\aspnet-WebApplication1-20170509023603.mdf' as database 'aspnet-WebApplication1-20170509023603'.)
How do I fix it?
May 09, 2017 04:17 PM|PatriceSc|LINK
Seems you have a hardcoded path in your web.config file? Usually you are using something such as
|DataDirectory|\yourDataFile.mdf which points to App_Data regardless of where your app is actually installed.
Edit: this is discussed at
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx for the AttachDBFilename keyword. BTW this is your own VM or app service. I'm not sure it works in this later case (I doubt they install a local db engine).
Anyway beyond a proof of concept it's likely best to connect explicitely to a SQL Server instance rather than to use an App_Data database file (for example you couldn't then create multiple instance for your web sites as they would have each their own data
file rather than sharing a db etc...)