Bryan
Bryan

Reputation: 8697

Establishing connection of SQL Server 2008 with VS2012 project via web.config file

I'm trying to connect my database from my SQL Server to my asp.net project through the web.config file. I found code like this which should be able to connect my SQL Server and ASP.net project together properly. However after adding this code, I got this error.

This is my SQL Server connection string that is supposed to be place in web.config:

<connectionStrings>
   <add name="MyConnectionString" 
        connectionString="Data Source=sergio-desktop\sqlexpress;Initial 
                          Catalog=MyDatabase;User ID=userName;Password=password"
        providerName="System.Data.SqlClient" />
</connectionStrings>

And this is the error

enter image description here

I'm also not very sure if the syntax of my connection string to establish connection between the two is correct.

Upvotes: 0

Views: 213

Answers (1)

Rab
Rab

Reputation: 35582

As the error suggests, the connection element should not go in system.web section. it should go in configuration section of your web.config

as

<configuration>
<connectionStrings>
---

Upvotes: 1

Related Questions