error occurred while establishing a connection to SQL Server
问题 If I have my connection string in the web.config like this (added line feeds for better readability): <add name="conn" connectionString="Data Source=(localdb)\v11.0; Initial Catalog=MyDB; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=D:\Products.mdf" providerName="System.Data.SqlClient"/> The connection works and I can connect to the database in the database explorer. When I specify the connectionstring in code or use ConfigurationManager to get it it doesn't work: