1

I have created simple database table in Visual Studio 2015 called Users and updated it.

enter image description here

I want to connect it with my project, so after I fill in my text fields and press 'Sign Up' button, it can get saved to database. I am aware that I'll have to use string connections and other stuff to connect it, but how do I first connect this project with web.config ?

enter image description here

I have seen people dragging this table to Registration form code, so it would automatically create a connection with web-config, but it didn't work for me.

How do I reference my database from web.config correctly ?

3
  • Depends where your database is stored. Is it sitting in your solution somewhere? Commented Apr 26, 2017 at 15:38
  • I'm not sure if I understand your question, but I created table in Visual Studio using SQL Database. I haven't used sql management studio. If that's what you mean. Commented Apr 26, 2017 at 15:40
  • 1
    It's not. When you create a database, the MDF file; which is your database (as shown in your screenshot), is stored somewhere. The connection string would need to know where that file is. Commented Apr 26, 2017 at 15:49

1 Answer 1

2

Right-click on MyDatabase.mdf and in the properties panel you will see the Connection String. Copy that into the web config in the ConnectionStrings node:

  <connectionStrings>
    <add name="MyDatabase" connectionString="[Paste Connection String Here]"/>
  </connectionStrings>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was it! Also apologizes to the @KSib, I've just started ASP.NET so don't understand quite lot of terms. : )

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.