I tested all the answers here, but no one worked for me. So I studied the problem a bit, and finally I found the right connection string. To get this line, follow these steps:
1. in the name of the project:
but. right click on the project name,
b. Click Add
from. select the SQL Server database (obviously, you can rename it as you wish).
Now a new new database will be added to your project.
2. The database is visible in the "Server Explorer" window.
3. Left-click the database name in the "Server Explorer" window; now check the Solution Explorer window and you will find the "Connection String" along with the provider, state, type, version.
4. Copy the attached connection string and place it in the Page_Load method:
string source = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\x\x\documents\visual studio 2013\Projects\WebApplication3\WebApplication3\App_Data\Product.mdf;Integrated Security=True"; SqlConnection conn = new SqlConnection(source); conn.Open();
I renamed my database as Product. In addition, in "AttachDbFilename" you must replace "c: \ x \ x \ documents \" with your path to the physical address of the .mdf file.
This worked for me, but I have to mention that this method works for VS2012 and VS2013. I do not know about other versions.
user3143076
source share