remote procedure call (RPC) protocol stream is incorrect - c#

I use entityframework 5.0. I have so many test. If I run a test alone it passes, if I run this with the others eachother in the same time, it does not pass. There is no contact between the tests. Everytime one same query was sent. It would not be modified.
**query:**
insert [dbo].[Patient]
([AddressId],
[FirstName],
[LastName],
[MiddleName],
[MuthersName],
[Sex],
[BirthDate],
[TAJNumber],
[Height],
[Weight],
[PhoneMobil],
[PhoneHome],
[Email],
[OtherDisease])
values (13 /* #0 */,
'Peter' /* #1 */,
'Peter' /* #2 */,
'Peter' /* #3 */,
'Maria' /* #4 */,
1 /* #5 */,
'1991-07-04T00:00:00' /* #6 */,
'5464845' /* #7 */,
170 /* #8 */,
66 /* #9 */,
'00456249864' /* #10 */,
'00456249864' /* #11 */,
'alma22#mailmetrash.com' /* #12 */,
null)
select [Id]
from [dbo].[Patient]
where ##ROWCOUNT > 0
and [Id] = scope_identity()
**WARN:**
System.Data.SqlClient.SqlException (0x80131904): The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 9 ("#6"): The supplied value is not a valid instance of data type datetime2. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledCommand.ExecuteDbDataReader(CommandBehavior behavior)
ClientConnectionId:c184fe10-8d28-4b0b-96bf-395796cd0e29
**exception:**
Test Name: VM_PatientRegistration_Insert
Test FullName: **Insert
Test Source: **line 23
Test Outcome: Failed
Test Duration: 0:00:01,0018114
Result Message:
Test method TandoCare.Desktop.Test.ViewModel.PatientRegistrationViewModelTest.VM_PatientRegistration_Insert threw exception:
System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 9 ("#6"): The supplied value is not a valid instance of data type datetime2. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.
Result StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
at System.Data.Entity.DbContext.SaveChanges()
at TandoCare.Infrastructure.Data.UnitOfWork.UnitOfWorkBase`1.Save() in ** at TandoCare.Desktop.Test.ViewModel.PatientRegistrationViewModelTest.VM_PatientRegistration_Insert() in *** :line 55

I faced this problem when I tried to insert a new row with a column of float data type. The same exception as yours was thrown when I tried to insert Infinity or NaN values, which are not supported by SQL Server.
if you're using Entity Framework, It's recommended to use the HibernatingRhinos assembly. You can trace generated queries and detect the parameter that caused your problem.
SQL Profiler will not help you if your using TPT (Table-Per-Type).

I was issuing a SQLCommand with a select command and I had the error :
The incoming tabular data stream (TDS) remote procedure call (RPC)
protocol stream is incorrect. The RPC name is invalid.
Because I was calling a SQLCommand with a command type of CommandType.StoredProcedure.
Changing this to CommandType.Text fixed my problem.
System.Data.SqlClient.SqlCommand result = new SqlCommand(GetSQLSelectCommande());
if (FromDate == default(DateTime) || isEqualDay(FromDate, DateTime.Now))
{
FromDate.AddMonths(-1);
}
ToDate = new DateTime(ToDate.Year, ToDate.Month, ToDate.Day, 23, 59, 59);
result.Parameters.Clear();
result.CommandType = CommandType.Text;
result.Parameters.Add("#IdClient", SqlDbType.Int).Value = this.IdClient;
result.Parameters.Add("#dateDebut", SqlDbType.DateTime).Value = this.FromDate;
result.Parameters.Add("#dateFin", SqlDbType.DateTime).Value = this.ToDate;
result.Parameters.Add("#langue", SqlDbType.Int).Value = (Offix.Culture.GetCulture() == Offix.EnumLangue.ofxFrancais ? 5 : 3);

I think the issue is coming from your parameter #6. It seems that the format is invalid.
Have you tried some thing like this to create the date? :
new DateTime(1991,07,04).ToShortDateString()

Related

sql exception "physical connection is not usable" on a specific column in specific table

I have a winforms desktop app. It works on the server computer, where the db is, but on another computer, with win 8.1, it throws the error only when selecting 2 specific columns from 2 tables. First column is image type, the other is nchar(250) type. I'm using EF6, but even if I write raw sql, I get the same exception. The exception does not occur on client machines running win 10.
System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
at System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
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)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
--- End of inner exception stack trace ---
The connection string is Data Source=172.16.100.100;Initial Catalog=ss;Persist Security Info=True;User ID=sa;Password=pass;MultipleActiveResultSets=True
As I said every code, that selects the mentioned columns from the db triggers it. Eg:
context.ProblematicTable.ToList() ; context.ProblematicTable.Select(x=>x.ProblemColumn) ;
context.ExecuteStoreQuery<ProblematicTable>("select ProblematicColumn from ProblematicTable")
Selecting other columns does not raise errors. Eg:
context.ProblematicTable.Select(x=>x.AnyOtherColumn)

how to get or set database error user friendly for user .net core

I am developing .net core web application with angular and typescript, what I need is to track error in user friendly manner.
public JsonResult Post([FromBody] Data product)
{
Response.StatusCode = 200;
try
{
repo.Insert(new TblStudentRegisteration() { RgNo = product.rgno , Name = product.name , FatherName = product.FatherName});
}
catch (Exception e)
{
Response.StatusCode = 400;
return Json(e.ToString());
}
return Json("ok");
}
Where RGNo is primary key, What I need is whenever any error raised by Database, Error it return in user friendly manner?
Like when user give RgNo two times exception throws like
"Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_tbl_StudentRegisteration'. Cannot insert duplicate key in object 'dbo.tbl_StudentRegisteration'.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary2 parameterValues)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Tuple2 parameters)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func2 operation)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IReadOnlyList1 entries)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
at RepositoryData.Repository`1.Insert(T entity) in
Where I understand that this is the problem of duplicate entries, from this given sentence.
Violation of PRIMARY KEY constraint 'PK_tbl_StudentRegisteration'. Cannot insert duplicate key in object 'dbo.tbl_StudentRegisteration'
How User understand this? until and unless we define them in a best way.
is there easiest way to do this?
EDIT
One thing I want to clear that, I know there are many ways to do this like, first check whether this RgNo exist, and then post it to DB, but there are also some others excpetion, use of ex.Message will give short form, etc, but I want something easier which makes my life easier every time.

Asp.net web form "The wait operation timed out"

I have a web form built to retrieve data from a reporting server. I don't have rights to create an index on the table I'm querying in that server, and the query is very, very slow on the text lookup. I've tried optimizing what I can in the query, but it's just going to be slow. So I need to find a way to avoid getting the timeout in the webpage itself. I have reviewed several similar questions, I set a crazy high connection timeout, but I'm still getting the wait operation timeout on the button click. The timeout happens after 30 seconds, even though I have set such a high connection timeout. I don't know if it's the web config, but I'm not using the connection string defined in my webconfig, just this one here in the codebehind. The query does not time out in SSMS, only when accessing the data from the webform (which technically is using my login credentials in the connection string, so there is no sort of permissions issues, other portions run fine). Is there any where else I need to increase the timeout for the page?
Connection string (un/pw x'ed out for privacy):
server=lxxxxxx.resources.xxx; Initial Catalog=pxxxxxxxx;User ID=mfeXXXXX;Password=XXXXXX;Trusted_Connection=False; Connection Timeout=10000"
query that times out, if that helps:
protected void btnSearchFeedback_Click(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter sdaFeedBack = new SqlDataAdapter("SELECT CTIR.portion_ID, IB.Item_ID as [Item ID], CTIR.Item_DBkey as [Item DB Key], CTIR.Feedback as [Feedback], CTA.date as [Date],CTA.Candidate_ID as [Candidate ID] FROM Canxxxxxxx CTIR WITH (NOLOCK) left join Ixxxxx IB WITH (NOLOCK) ON CTIR.xxxxx = IB.xxxxx left join Cxxxxxx CTA WITH (NOLOCK) ON CTxxxxxx = CTxxxxxxx where (ctir.portion_id in (" + portionIDTextBox.Text + ") ) AND (len(CTIR.Feedback) > 0) and CTA.Date > '2015-02-01 00:00:00.000' order by [Date]", con);
DataSet dtFeedBack = new DataSet();
sdaFeedBack.Fill(dtFeedBack);
ViewState["dtFeedback"] = dtFeedBack;
rptFeedBack.DataSource = dtFeedBack;
rptFeedBack.DataBind();
con.Close();
}
Again, x'ed out table names for security. So I am trying to see if there is another location I need to set the connection timeout to a higher number to avoid the "Server Error in '/' Application. The wait operation timed out", or is this something that needs to be handled on the server side?
This is the exact error:
Server Error in '/' Application.
The wait operation timed out
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The wait operation timed out
stack trace:
[Win32Exception (0x80004005): The wait operation timed out]
[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +2434922
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +5736592
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +285
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731
System.Data.SqlClient.SqlDataReader.TrySetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo) +198
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +2852
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58
System.Data.SqlClient.SqlDataReader.get_MetaData() +89
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +379
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest) +2026
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +375
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +240
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +12
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +139
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +136
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +88
FeedBackForm.btnSearchFeedback_Click(Object sender, EventArgs e) in C:\Users\mfelchlin\Documents\Visual Studio 2015\WebSites\devFormsSite\FeedBackForm.aspx.cs:27
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9696694
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639
sdaFeedBack.SelectCommand.CommandTimeout=120; //or some other number of seconds.
Setting the timeout on the connection determines how long to wait for the connection to open, not for the command to execute.

Command timeout SQL Server 2014 + Entity Framework

I have installed SQL Server 2014 on my new PC yesterday, it was working until I restarted my PC, now I am getting this error.
I have started / restarted SQL Server services etc..
I can still connect from Management Studio.
When adding EF model to my asp.net project, it can list databases and get tables to generate EF model, but I can't do anything with the database because of this timeout exception, database is almost empty (only 1 table with 1 user in) and I am executing simple queries (like select, add)
using(var db = new TestEntities())
{
var _user = db.Users.FirstOrDefault(); // timeout exception
}
Unhandled Exception: System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception: The wait operation timed out
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func3 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.<GetResults>b__6()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.<GetResults>b__5()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable1 sequence)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable1 query, Expression queryRoot)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable1 source)
Set the timeout on the command
SqlCommand.CommandTimeout
There is probably another problem
And test a simple select like select ##versino
Press window + r > "services.msc" > SQL Server (MSSQLSERVER) > Right Click > Start
The sql server instance is closed therefore server couldn't respond.
Could it be that the TCP/IP protocol is not enabled? Check SQL Server Configuration Manager.
It could also be that it's not accepting remote connections. For that, you need to check with SQL Server Management Studio, server properties, Connections.

WCF Data Services with Entity Framework with View that contains Xml

We have a SQL server View that contains some XML fields.
We created a DBContext using Entity Framework (v5) Database first.
We added a WCF Data Service and assigned it to the DBContext like:
public class ProductsDBSvc : DataService<ProductsDBEntities>
{
config.UseVerboseErrors = true;
config.SetEntitySetPageSize("vw_Release", 100);
config.SetEntitySetAccessRule("vw_Release", EntitySetRights.AllRead);
}
Using a browser we make this call http://localhost:60606/Products/vw_Release but it returns the below error:
<m:internalexception>
<m:message>
The XML data type cannot be compared or sorted, except when using the IS NULL operator.
</m:message>
<m:type>System.Data.SqlClient.SqlException</m:type>
<m:stacktrace>
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
</m:stacktrace>
</m:internalexception>
The Error means that we cannot use the XML column in the order by clause and this is a SQL Server error.
While we never asked for an order by in the query.
So we activated the SQL Profiler and we found out the following info:
1- OData WCF Services with Entity Framework referring to a view (rather than a table) sends a SQL Statement that includes order by for each column like this:
SELECT
[vw_Release].[ID] AS [ID],
[vw_Release].[TypeNameXml] AS [TypeNameXml],
[vw_Release].[StatusNameXml] AS [StatusNameXml],
[vw_Release].[Created] AS [Created],
[vw_Release].[Modified] AS [Modified],
FROM [dbo].[vw_Release] AS [vw_Release]) AS [Extent1]
) AS [Project1]
ORDER BY [Project1].[Created] ASC,
[Project1].[ID] ASC, [Project1].[Modified] ASC,
[Project1].[StatusNameXml] ASC, [Project1].[TypeNameXml] ASC
2- Getting the same information but just reading from a table instead of a view sends:
SELECT
[Release].[ID] AS [ID],
[Release].[TypeNameXml] AS [TypeNameXml],
[Release].[StatusNameXml] AS [StatusNameXml],
[Release].[Created] AS [Created],
[Release].[Modified] AS [Modified],
FROM [dbo].[Release] AS [vw_Release]) AS [Extent1]
ORDER BY [Project1].[Created] ASC,
[Extent1].[ID] ASC
All what we did is out of the box functionality of everything, and can be easily reproduced. Is there a way around to tell the WCF Data Service not to include order by for all columns?
I believe the issue is related to the Config.SetEntityPage size, can you try without setting that and see what happens.
Problem with WCF Data Service (OData), SetEntitySetPageSize and custom operations

Categories

Resources