How do you connect to a local SQL server database in asp.net using Visual Studio 2013? I'm not talking about a remote access connection. In this case, the SQL database is located in the App_Data folder that is at the root of the web application. I want to be able to query the database from the c# file that is connected to the asp.net application and display the data on a label. I have searched for an answer for well over an hour and nothing seems to show up.
-
I would think you have to attach it first unless you were using SQL Compact Edition.SteveFerg– SteveFerg2015-06-13 21:13:43 +00:00Commented Jun 13, 2015 at 21:13
-
@SteveFerg I created the web application. I created the asp.net page. Then I added database into the App_Data folder. Next I added a few tables in the database. Now I want to query the database from the c# file attached to my asp.net page.Thomas McEwen– Thomas McEwen2015-06-13 21:20:34 +00:00Commented Jun 13, 2015 at 21:20
Add a comment
|
1 Answer
for your web.config connection string, try something like:
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=c:\inetpub\wwwroot\webite\app_date\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True" />
(modified accordingly)
1 Comment
Thomas McEwen
Thank you so much. That was the problem. My connection string was screwed up.