Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationManager.ConnectionStrings[0].Name return LocalSqlServer

I have a WCF web service and I call the WCF method with Ajax (JQuery).

I tested my web service with WcfTestClient.exe and it works well.

But when I call the web service method with Jquery, I have an error (object reference not set to an instance of an object).

I debug and I have this in my **ConfigurationManager.ConnectionStrings[0].Name** : *LocalSqlServer*.

My dataBase key is RMS and not LocalSqlServer.

I have 2 projects in my solution, the WCF and an application console that will do to turn back the web service.

Here my solution

enter image description here

Here is my web.config :

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="RMS" connectionString="Data Source=192.168.40.137;Initial Catalog=RMS_Database;Persist Security Info=True;User ID=****;Password=****"
  providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="16384"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />  
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
          <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

I created a .asmx web service and I succeeded JQuery calls. I think my solution is not using the correct web.config. How to solve this?

like image 775
Jayce Avatar asked Mar 10 '14 11:03

Jayce


1 Answers

Your first post is probably just missing the following entry:

<clear />

Before the following entry:

 <add name="RMS" connectionString="Data Source=192.168.40.137;Initial Catalog=RMS_Database;Persist Security Info=True;User ID=****;Password=****"
  providerName="System.Data.SqlClient" />

Description: Without the clear entry the default machine.config connection string is read. This entry is called LocalSqlServer. Clear avoids this.

like image 152
Naha Avatar answered Nov 10 '22 01:11

Naha