I have added a database file (.mdf
) to my application using Visual Studio built-in functionality. Database is in the App_Data
folder. It is running fin
The fix for me was making sure I had the correct project set for startup in the solution. Right click project and "Set as Startup Project"
The whole User Instance and AttachDbFileName= approach is flawed - at best! Also, it's only supported by the Express edition of SQL Server - so if your hoster has anything other than Expres, you're basically screwed.
The real solution in my opinion would be to
install SQL Server Management Studio Express
create your database in SSMS Express, give it a logical name (e.g. MyDatabase
)
connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:
Data Source=.\\SQLEXPRESS;Database=MyDatabase;Integrated Security=True
and everything else is exactly the same as before...
Now, when you go and upload your web site to the hosting site, you need to get the necessary SQL scripts to create and populate your database on the hosting site - you can do this by using Tasks > Generate Scripts
from the SSMS Express tool, or by some other means.
Then, on the hosting site, you need to execute those SQL scripts to create and populate your database (and later on: execute the change scripts to keep the database up to date).
Your connection string will also most likely change to something like:
Server=(ip-address-or-name);Database=MyDatabase;User ID=YourUserIdHere;Pwd=YourPassword
since the hosting provider doesn't use the SQLEXPRESS
named instance (but most likely a default instance without any name). You need to ask your provider for the details - it could be that you have to provide some other instance name! That's totally up to the provider, we cannot know that - you'll have to ask and find out.