底层连接已关闭:连接意外关闭 - wcf
我在我的WPF项目中使用WCF服务。 我有大量的数据,大约有847000条记录在表中。此异常扔在客户端底层连接已关闭:连接意外关闭 - wcf
proxy.ServicesClient client = new proxy.ServicesClient();
var result = client.GetCustomers(); // here throws ('**ComunicationException was unhandled by user code**: *The underlying connection was closed: The connection was closed unexpectedly*.')
在我的app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServices" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:5302/WpfStoreService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServices"
contract="proxy.IServices" name="BasicHttpBinding_IServices" />
</client>
</system.serviceModel>
</configuration>
在Web.Config中
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="AdventureWorksLTConnectionString" connectionString="Data Source=.;Initial Catalog=AdventureWorksLT;Integrated Security=True" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServices" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="52428899">
<readerQuotas maxDepth="128"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
你对WCF服务这个问题?
除非您已将其重写到其他位置,否则默认的数据库连接超时将成为问题。
我认为它可以被禁用,如果您将连接超时值设置为0,但这取决于DbConnection实施;
尝试将此添加到您的连接字符串。 Connect Timeout=0
"Data Source=.;Initial Catalog=AdventureWorksLT;Integrated Security=True;Connect Timeout=0"
谢谢你的回复,但不是工作:( 我注意到这个异常发生在大量的数据。如果我减少记录的数量例如1000(现在我有847 000 )它可以工作 – user746499 2013-03-26 13:37:09
任何想法?...... – user746499 2013-03-27 07:47:39
只有一个其他的真的......不要在一个事务中选择847000个记录,而应该集中精力重新设计接口,以便使用更小的数据块工作 – 2013-03-27 09:47:05
有超时在你的配置:是不是那些10分钟后存在的问题? – GameAlchemist 2013-03-26 09:36:27
不,这个异常发生在30 - 40秒 – user746499 2013-03-26 09:44:21