0

I get this error message

The connection string 'MyConnection' in the application's configuration file does not contain the required providerName attribute."

I read this question The connection string 'MyConnection' in the application's configuration file does not contain the required providerName attribute." about this same issue.

In my case the providerName="System.Data.SqlClient" is correctly in my web.config file in local but disappear when I do a publish on my production server (build in release). I don't have the problem on my local server.

EDIT

Here is my release config file

<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <!--
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an attribute "name" that has a value of "MyDB".

    <connectionStrings>
      <add name="MyDB" 
        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
  -->
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <!--
      In the example below, the "Replace" transform will replace the entire 
      <customErrors> section of your web.config file.
      Note that because there is only one customErrors section under the 
      <system.web> node, there is no need to use the "xdt:Locator" attribute.

      <customErrors defaultRedirect="GenericError.htm"
        mode="RemoteOnly" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>
    -->
  </system.web>
</configuration>
Community
  • 1
  • 1
Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200
  • 1
    Most likety caused by web.config transformation http://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx check whats in your web.release.config – Esko Sep 12 '14 at 10:47
  • When you publish, any configuration transforms are applied. Check if you have something like Web.Config.Production in your solution – helb Sep 12 '14 at 10:47
  • Connection strings get rewritten by the publish process. Did you set connection strings in the "Settings" section of the "Publish" dialog? – spender Sep 12 '14 at 10:47
  • Usually you don't overwrite the `web.config` file on the production server with the one released by the build or publish process on your dev machine. You just edit it to be according to the settings on that server. In this case, manually edit the file to include your `providerName`. – Alex Barac Sep 12 '14 at 10:48
  • 1
    @AlexBarac : It seems you have much to learn about "Publish" from VisualStudio and msdeploy. Visual Studio allows you to apply transformations to your web.config dependent on the selected solution configuration in vs, which negates the need to make any manual edits to files deployed to the server. – spender Sep 12 '14 at 10:50
  • @spender I guess you're right, but still, my method always kept me out of trouble, that's why I mentioned it – Alex Barac Sep 12 '14 at 11:00

1 Answers1

0

Use this for your release config file:

<connectionStrings>
    <add name="MyDB" 
      connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)" providerName="System.Data.SqlClient" />
  </connectionStrings>

ConnectionString for your local is being change by release config file. So if you declare providerName in your local config, that will be no use if you publish your release files. you need to declare the providerName in your release config file also.

jomsk1e
  • 3,585
  • 7
  • 34
  • 59