0

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.

2
  • I would think you have to attach it first unless you were using SQL Compact Edition. Commented 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. Commented Jun 13, 2015 at 21:20

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. That was the problem. My connection string was screwed up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.