Connection to SQL Server Database inside Visual Studio connectionString error

0

I've import my SQL 2005 database to my project and i am trying to connect to the database using the web.config

But I've this error when I add the connectionString to the web.config.

    <add name="strConn" connectionString="Data Source=.\sqlexpress;Initial Catalog=intranet_db;Integrated Security=True"
     providerName="System.Data.SqlClient"/>

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid. Detailed Error Information:

  • Module IIS Web Core
  • Notification Unknown
  • Handler Not yet determined
  • Error Code 0x80070032
  • Config Error The configuration section 'add' cannot be read because it is missing a section declaration
  • Config File \?\C:\Users\user\Documents\Visual Studio 2012\Projects\test\test\web.config
  • Requested URL localhost:64198/
  • Physical Path
  • Logon Method Not yet determined
  • Logon User Not yet determined
  • Request Tracing Directory
    C:\Users\user\Documents\IISExpress\TraceLogFiles\

    Am I doing it wrong? What should I add in the web.config?

Thanks.

c#
asp.net
asked on Stack Overflow Mar 5, 2014 by JohnDoe4136

3 Answers

1

it should be something like this

<connectionStrings>
        <add name="connectionString" connectionString="Provider=SQLOLEDB.1;Data Source=dbhostname;Persist Security Info=True;Password='password';User ID='username';Initial Catalog=dbname" />
</connectionStrings>
answered on Stack Overflow Mar 5, 2014 by Saddam Abu Ghaida
1

Please make sure you put the "add" tag in the correct place. I'm able to reproduce your error when I place it i wrong section. Your web.config file should look like this:

<configuration>
  <connectionStrings>
    <add name="strConn" connectionString="Data Source=.\sqlexpress;Initial Catalog=intranet_db;Integrated Security=True"
     providerName="System.Data.SqlClient"/>
   </connectionStrings>
</configuration>
answered on Stack Overflow Mar 5, 2014 by Johan
0

have a look at http://www.connectionstrings.com/ it has examples of what they should be.

looking at you connection string make sure the instance name ./SqlExpress is correct.

A quick test would be to load sql manager and connect with the ./SqlExpress

Standard Security

Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;

Trusted Connection Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

to give you a better answer would require knowing how you want to connect to the database.

answered on Stack Overflow Mar 5, 2014 by Anthony • edited Mar 5, 2014 by Anthony

User contributions licensed under CC BY-SA 3.0