Format of the initialization string does not conform to specification starting at index 0

Banford picture Banford · Mar 7, 2011 · Viewed 70.3k times · Source

I have an ASP.Net MVC application which runs fine on my local development machine. But when deployed to IIS7 gives the following error when trying to log in:

Format of the initialization string does not conform to specification starting at index 0

Most people who post this error resolve it by changing their connection string in some way. However my connection string on the local and deployed application are the same. The connection string is like this:

<add name="ApplicationServices" connectionString="Data Source=*server*\*instance*;Initial Catalog=*database*;Integrated Security=True;"
      providerName="System.Data.SqlClient" />

What is causing this error in my case?

Answer

Guru picture Guru · Jun 8, 2012

Format of the initialization string does not conform to specification starting at index 0

Web.config :

<connectionStrings>
    <add name="TestDataConnectionString" connectionString="Data Source=.\SQLExpress;Initial Catalog=TestData;User ID=satest;Password=satest"
     />
  </connectionStrings>

In aspx.cs Page the code must be written in the below format :

SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["TestDataConnectionString"].ToString());