{"action":"created","issue":{"url":"https://api.github.com/repos/npgsql/npgsql/issues/1354","repository_url":"https://api.github.com/repos/npgsql/npgsql","labels_url":"https://api.github.com/repos/npgsql/npgsql/issues/1354/labels{/name}","comments_url":"https://api.github.com/repos/npgsql/npgsql/issues/1354/comments","events_url":"https://api.github.com/repos/npgsql/npgsql/issues/1354/events","html_url":"https://github.com/npgsql/npgsql/issues/1354","id":187917047,"number":1354,"title":"Exception while reading from stream","user":{"login":"dholakiyaankit","id":6862074,"avatar_url":"https://avatars.githubusercontent.com/u/6862074?v=3","gravatar_id":"","url":"https://api.github.com/users/dholakiyaankit","html_url":"https://github.com/dholakiyaankit","followers_url":"https://api.github.com/users/dholakiyaankit/followers","following_url":"https://api.github.com/users/dholakiyaankit/following{/other_user}","gists_url":"https://api.github.com/users/dholakiyaankit/gists{/gist_id}","starred_url":"https://api.github.com/users/dholakiyaankit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dholakiyaankit/subscriptions","organizations_url":"https://api.github.com/users/dholakiyaankit/orgs","repos_url":"https://api.github.com/users/dholakiyaankit/repos","events_url":"https://api.github.com/users/dholakiyaankit/events{/privacy}","received_events_url":"https://api.github.com/users/dholakiyaankit/received_events","type":"User","site_admin":false},"labels":[{"id":278720744,"url":"https://api.github.com/repos/npgsql/npgsql/labels/waiting%20for%20answer","name":"waiting for answer","color":"fbca04","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-08T07:03:55Z","updated_at":"2016-12-07T09:16:09Z","closed_at":"2016-12-07T09:16:09Z","body":"I am using with EntityFramework6.Npgsql\r\nI have two projects in both I have installed the same package\r\n\r\nEntityFramework6.Npgsql 3.1.1.0\r\nNpgsql                               3.1.8.0\r\n\r\nI am getting this exception : Exception while reading from stream\r\n\r\n```\r\nNpgsql.NpgsqlException (0x80004005): Exception while reading from stream ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond\r\n   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)\r\n   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)\r\n   --- End of inner exception stack trace ---\r\n   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)\r\n   at Npgsql.ReadBuffer.Ensure(Int32 count, Boolean dontBreakOnTimeouts)\r\n   at Npgsql.ReadBuffer.Ensure(Int32 count, Boolean dontBreakOnTimeouts)\r\n   at Npgsql.NpgsqlConnector.DoReadMessage(DataRowLoadingMode dataRowLoadingMode, Boolean isPrependedMessage)\r\n   at Npgsql.NpgsqlConnector.ReadMessageWithPrepended(DataRowLoadingMode dataRowLoadingMode)\r\n   at Npgsql.NpgsqlConnector.ReadExpecting[T]()\r\n   at Npgsql.NpgsqlDataReader.NextResultInternal()\r\n   at Npgsql.NpgsqlDataReader.NextResult()\r\n   at Npgsql.NpgsqlCommand.Execute(CommandBehavior behavior)\r\n   at Npgsql.NpgsqlCommand.ExecuteNonQueryInternal()\r\n   at Npgsql.NpgsqlCommand.ExecuteNonQuery()\r\n   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)\r\n   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(MigrationStatement migrationStatement, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(MigrationStatement migrationStatement, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinTransaction(IEnumerable`1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinNewTransaction(IEnumerable`1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)\r\n   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass30.<ExecuteStatements>b__2e()\r\n   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation)\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements, DbTransaction existingTransaction)\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)\r\n   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)\r\n   at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)\r\n   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)\r\n   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)\r\n   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)\r\n   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)\r\n   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)\r\n   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()\r\n   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)\r\n   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)\r\n   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)\r\n   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)\r\n   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()\r\n   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)\r\n   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)\r\n   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)\r\n   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)\r\n   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()\r\n   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)\r\nException while reading from stream`\r\n```\r\nMy web.config looks like this:\r\n```xml\r\n<add name=\"cstContext\" connectionString=\"Server=10.2.7.35;Port=5432;User Id=tzell;Password=asdf;Database=asdf;Pooling=false;CommandTimeout=0;\" providerName=\"Npgsql\" />\r\n\r\n<system.data>\r\n    <DbProviderFactories>\r\n      <!--for EF4.x and EF6.0.x -->\r\n      <!--you may need this. if you don't modify machine.config-->\r\n      <remove invariant=\"Npgsql\" />\r\n      <add name=\"Npgsql - .Net Data Provider for PostgreSQL\" invariant=\"Npgsql\" description=\".Net Data Provider for PostgreSQL\" type=\"Npgsql.NpgsqlFactory, Npgsql, Version=3.1.8.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7\" />\r\n    </DbProviderFactories>\r\n  </system.data>\r\n  <!--<defaultConnectionFactory type=\"System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework\">\r\n      <parameters>\r\n        <parameter value=\"mssqllocaldb\" />\r\n      </parameters>\r\n    </defaultConnectionFactory>\r\n    <providers>\r\n      <provider invariantName=\"System.Data.SqlClient\" type=\"System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer\" />\r\n    </providers>-->\r\n  <entityFramework>\r\n    <providers>\r\n      <!--for EF6.0.x -->\r\n      <!--you need this. add it manually-->\r\n      <provider invariantName=\"Npgsql\" type=\"Npgsql.NpgsqlServices, EntityFramework6.Npgsql\" />\r\n      <!--<provider invariantName=\"Devart.Data.PostgreSql\" type=\"Devart.Data.PostgreSql.Entity.PgSqlEntityProviderServices, Devart.Data.PostgreSql.Entity.EF6, Version=7.6.743.0, Culture=neutral, PublicKeyToken=09af7300eec23701\" />-->\r\n    </providers>\r\n  </entityFramework>`\r\n```\r\n\r\nMy App.Config\r\n```xml\r\n<entityFramework>\r\n    <defaultConnectionFactory type=\"System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework\">\r\n      <parameters>\r\n        <parameter value=\"mssqllocaldb\" />\r\n      </parameters>\r\n    </defaultConnectionFactory>\r\n    <providers>\r\n      \r\n      <provider invariantName=\"Npgsql\" type=\"Npgsql.NpgsqlServices, EntityFramework6.Npgsql\" />\r\n    </providers>\r\n  </entityFramework>`\r\n\r\n` <runtime>\r\n    <assemblyBinding xmlns=\"urn:schemas-microsoft-com:asm.v1\">\r\n      <dependentAssembly>\r\n        <assemblyIdentity name=\"Newtonsoft.Json\" publicKeyToken=\"30ad4fe6b2a6aeed\" culture=\"neutral\" />\r\n        <bindingRedirect oldVersion=\"0.0.0.0-6.0.0.0\" newVersion=\"6.0.0.0\" />\r\n      </dependentAssembly>\r\n      <dependentAssembly>\r\n        <assemblyIdentity name=\"Npgsql\" publicKeyToken=\"5d8b90d52f46fda7\" culture=\"neutral\" />\r\n        <bindingRedirect oldVersion=\"0.0.0.0-3.1.8.0\" newVersion=\"3.1.8.0\" />\r\n      </dependentAssembly>\r\n    </assemblyBinding>\r\n  </runtime>\r\n```\r\n\r\nI have been trying this from 2 days I do not know what I am doing wrong with this. Please help me.\r\n\r\nThere are 200000 records in table\r\n"},"comment":{"url":"https://api.github.com/repos/npgsql/npgsql/issues/comments/265395663","html_url":"https://github.com/npgsql/npgsql/issues/1354#issuecomment-265395663","issue_url":"https://api.github.com/repos/npgsql/npgsql/issues/1354","id":265395663,"user":{"login":"roji","id":1862641,"avatar_url":"https://avatars.githubusercontent.com/u/1862641?v=3","gravatar_id":"","url":"https://api.github.com/users/roji","html_url":"https://github.com/roji","followers_url":"https://api.github.com/users/roji/followers","following_url":"https://api.github.com/users/roji/following{/other_user}","gists_url":"https://api.github.com/users/roji/gists{/gist_id}","starred_url":"https://api.github.com/users/roji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roji/subscriptions","organizations_url":"https://api.github.com/users/roji/orgs","repos_url":"https://api.github.com/users/roji/repos","events_url":"https://api.github.com/users/roji/events{/privacy}","received_events_url":"https://api.github.com/users/roji/received_events","type":"User","site_admin":false},"created_at":"2016-12-07T09:16:09Z","updated_at":"2016-12-07T09:16:09Z","body":"Sorry it took so long to respond.\r\n\r\nA table with 3000000 rows and no indexing? Sounds like a pretty bad idea :) That's definitely something that could lead to timeout exceptions. Npgsql doesn't really play any role here, it's up to you to design your database properly and make sure queries don't run for too long. If really want to, you can disable timeouts altogether by passing `Command Timeout=0` in the connection string, but with a default of 30 seconds your queries are probably running for too long and you need to optimize things.\r\n\r\nRegarding InvalidCastException, again, I don't see it in the stack trace you posted. It's possible you have two different issues - one is the timeout, and another is some InvalidCastException caused by some specific problematic query. Try to separate the two and understand which is happening on which query (or queries).\r\n\r\nI'm going to close this as there doesn't seem to be anything relevant to Npgsql, but if you think you need more help don't hesitate to ask."}}
{"actor":{"display_login":"roji"}}