Search code examples
asp.netsql-serverdatabaseconnection-stringplesk

Connection String issue with inserting SQL Server


I am having some issues with inserting into my database. I'm hosting my website using Plesk and myLittleAdmin holds with my a SQL Server database.

The issues is that I can edit and delete items from a management page that shows all the items in the database, but as soon as I try add/insert an item into the database, I get this error

Error: System.InvalidOperationException: The connection string 'WatchDBv2Entities' in the application's configuration file does not contain the required providerName attribute."

When searching that people say I simply need to add providerName="System.Data.SqlClient" to WatchDBv2Entities, but no matter where I place it or what I do i still get errors.

Here is my connection string info:

<connectionStrings>
    <add name="WatchDBv2ConnectionString" 
         connectionString="Data Source=IPaddressofDBserver;Initial Catalog=WatchDBv2;Integrated Security=False;User ID=myusername;Password=mypassword;Connect Timeout=15;Encrypt=False;Packet Size=4096;" 
         providerName="System.Data.SqlClient" />
    <add name="WatchDBv2Entities"  
         connectionString="metadata=res://*/App_Code.ModelPresentation.csdl|res://*/App_Code.ModelPresentation.ssdl|res://*/App_Code.ModelPresentation.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=IPaddressofdbserver;initial catalog=WatchDBv2;integrated security=False;Persist Security Info=False;MultipleActiveResultSets=True;App=EntityFramework;"/>
</connectionStrings>

Any ideas would be greatly appreciated, thanks.


Solution

  • Since this is a connection string for Entity Framework with an .edmx model file, you need to specify the System.Data.EntityClient as the provider - not System.Data.SqlClient.

    Try this:

    <connectionStrings>
        <add name="WatchDBv2ConnectionString" 
             connectionString="Data Source=IPaddressofDBserver;Initial Catalog=WatchDBv2;Integrated Security=False;User ID=myusername;Password=mypassword;Connect Timeout=15;Encrypt=False;Packet Size=4096;" 
             providerName="System.Data.SqlClient" />
        <add name="WatchDBv2Entities"  
             connectionString="metadata=res://*/App_Code.ModelPresentation.csdl|res://*/App_Code.ModelPresentation.ssdl|res://*/App_Code.ModelPresentation.msl;provider=System.Data.SqlClient;provider connection string=&quot;data  source=IPaddressofdbserver;initial catalog=WatchDBv2;integrated security=False;Persist Security Info=False;MultipleActiveResultSets=True;App=EntityFramework;"
             providerName="System.Data.EntityClient" />  <!-- add the "EntityClient" as the provider! -->
    </connectionStrings>