WCF Data Services with Entity Framework with View that contains Xml - c#

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

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)

Calling stored procedure with table-valued parameter returns error

I have a class that I converts into a datatable so I can pass it as a TVP to a stored procedure.
The class contains just primitive types such as int, string, DateTime and Guid. After converting to a datatable, I call the stored procedure as follows:
var ids = connection.Query<int>("create_records", new { records }, commandType: CommandType.StoredProcedure);
On monitoring with SQL Server Profiler, I can see that the SQL is created correctly and I can execute this same SQL in T-SQL successfully.
However, when executing the stored procedure from code, I get the following error:
XML parsing: Row 1, Character 2112, invalid name character.
The exception is:
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.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, 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 Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior)
at Dapper.SqlMapper.<QueryImpl>d__125`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType)
The stored procedure inserts the TVP records into a couple of different tables, and at the end does the following:
SELECT id FROM #insertedRecords;
where #insertedRecords is a table-type with just 1 column (int) and is filled with the id's of the inserted records from the MERGE statement. Executing the stored procedure from within T-SQL with the same data passed by code works fine and records are inserted as expected.
UPDATE
After further debugging, the problem lies in an audit trigger associated with the table. An excerpt of the modified trigger is:
declare #xml xml;
set #xml = (SELECT '' as 'id/old', ISNULL(i.[id], '') as 'id/new'
FROM inserted AS i FOR XML PATH('inserts'));
insert into _temp select #xml;
Note: The select includes all the table's columns and not just the one. '_temp' is just a table with one column (xml).
The original problem that the trigger fails when inserting records from code still stands.
Is there an alternative way to output the columns in xml format without using FOR XML or at least disabling parsing?

Error in SQL Server stored procedure, timeout period elapsed

I am trying to use a stored procedure in which I am sending single parameter which I sent through ADO.NET C# code.
Now the problem is the stored procedure is getting called from my dev environment and when I deploy it to production I am getting exception of timeout elapse and it never reaches to the stored procedure (I have added logs to check if stored procedure is actually hit and at what stage it causes timeout).
Exception: System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
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.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, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at ProjectName.ViewModel.ClassViewModel.<>c__DisplayClasse.b__d()
I have no clue what is happening over production server. Please guide me over this issue.
There are a lot of questions for same error message but I am not able to find similar scenario for issue, like stored procedure not getting executed and still it causes timeout error.
I would have included stored procedure but it is very basic stored procedure.
Please help :)
Thanks,
Nikhil Chavan.
Have you tried to run your stored procedure in SQLServer and check if it runs successfully?
Have you tried setting the SqlCommand.CommandTimeout Property?
Have you checked your connection string if it is pointing to the correct DB and it is reachable?

Invalid object name : database object doesn't exist anymore

I'm working with 3 projects
- MVC4 website
- HTTP Handler
- Entity Framework data layer
Basicaly you have to fill out a form on the website, that transforms it into XML, sends it to the handler that returns XML and the website deals with the response. Both applications use the data layer library to update a database.
I've been doing test with the handler running localy and remotely on a webserver running IIS8. The first version I put on the webserver was working all right. Then I had to update the data layer library, and now i'm getting the "Invalid object name" error.
The thing is, the object anme is a table name that does not exist anymore in my data layer project, which really sounds weird to me.
I checked probably everything I could
- Connection strings are ok
- Rights to the database are ok
- the handler's DLL is up to dae
- the library' dll is up to date
I even stoped and restarted the application pool in which my handler is. Even now I tried it again with the handler running localy and it works fine, the error only happens when calling the handler on the remote server, and only since I made changes to the data layer library.
The only thing I think might be the cause is if there was something cached somewhere that I didn't know of.
Here's the stack trace, altough I didn't find any helpful information in it
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.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.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)

remote procedure call (RPC) protocol stream is incorrect

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()

Categories

Resources