c# - ConfigurationManager.ConnectionStrings[0].Name return LocalSqlServer -


i have wcf web service , call wcf method ajax (jquery).

i tested web service wcftestclient.exe , works well.

but when call web service method jquery, have error (object reference not set instance of object).

i debug , have in **configurationmanager.connectionstrings[0].name** : *localsqlserver*.

my database key rms , not localsqlserver.

i have 2 projects in solution, wcf , application console turn web service.

here solution

enter image description here

here 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 .asmx web service , succeeded jquery calls. think solution not using correct web.config. how solve this?

your first post missing following entry:

<clear /> 

before 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 clear entry default machine.config connection string read. entry called localsqlserver. clear avoids this.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -