Error in SQL Server stored procedure, timeout period elapsed - c#

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?

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)

SQL Server Id column seems to be reset in a C# app

All of a sudden the the web application for the database my nonprofit uses stopped functioning as it should. Basically I can't save any new entry. I can edit entries, but whenever I make new entry I get the error.
The app my organization uses is custom C# app. I was digging through the logs and I isolated the problem to a table which tracks user sessions.
NHibernate.Exceptions.GenericADOException: could not execute batch command.[SQL: SQL not available] ---> System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK__tUserSes__3214EC07F91B0D0B'. Cannot insert duplicate key in object 'SiteUser.tUserSession'. The duplicate key value is (7062).
That table has more than 300000 entries and the Id is clearly wrong, it's not the Id it should be. The more back I go in the logs the lower the Id number. It's like at some the Id counter was rested.
Whenever I try to add a new entry I get "System error occurred during request processing. Please contact the system administrator." which in logs looks like Cannot insert duplicate key in object 'SiteUser.tUserSession'. The duplicate key value is (7062).
I tracked down the logs to the point where the error appeared for the first time. It was actually at the beginning of the log file for the day 20180507.log
2018-05-07 00:24:29,990 WARN NHibernate.Util.ADOExceptionReporter - 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, 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.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalTransaction.Commit()
at System.Data.SqlClient.SqlTransaction.Commit()
at NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
ClientConnectionId:c6788280-f7cc-4c3a-9bf2-514f4df84fc9
Error Number:-2,State:0,Class:11
2018-05-07 00:24:30,006 ERROR NHibernate.Util.ADOExceptionReporter - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
2018-05-07 00:24:30,006 WARN NHibernate.Util.ADOExceptionReporter - System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
2018-05-07 00:24:30,006 ERROR NHibernate.Util.ADOExceptionReporter - The wait operation timed out
2018-05-07 00:24:30,006 ERROR NHibernate.Base.Transaction.With - Transaction failed.
NHibernate.Exceptions.GenericADOException: error performing isolated work[SQL: SQL not available] ---> 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.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.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalTransaction.Commit()
at System.Data.SqlClient.SqlTransaction.Commit()
at NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
--- End of inner exception stack trace ---
at NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
at NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
at NHibernate.Engine.TransactionHelper.DoWorkInNewTransaction(ISessionImplementor session)
at NHibernate.Id.MultipleHiLoPerTableGenerator.Generate(ISessionImplementor session, Object obj)
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at Quiddita.Business.Statistics.Services.StatisticsBusinessService.<>c__DisplayClass1.<CreateNewUserSession>b__0() in d:\Projects\CAT – Site Database\Source\Quiddita.Business.Statistics\Services\StatisticsBusinessService.cs:line 71
at NHibernate.Base.Transaction.With.Transaction(IsolationLevel level, Action transactional) in d:\Projects\CAT – Site Database\Source\NHibernate.Base\Transaction\With.Transaction.cs:line 39
2018-05-07 00:24:30,037 ERROR Quiddita.Aspects.Statistics.MethodBoundaryAspects.NewSessionAspectAttribute - NewSessionAspectAttribute.OnSuccess failed to execute.
NHibernate.Exceptions.GenericADOException: error performing isolated work[SQL: SQL not available] ---> 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.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.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalTransaction.Commit()
at System.Data.SqlClient.SqlTransaction.Commit()
at NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
--- End of inner exception stack trace ---
at NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
at NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
at NHibernate.Engine.TransactionHelper.DoWorkInNewTransaction(ISessionImplementor session)
at NHibernate.Id.MultipleHiLoPerTableGenerator.Generate(ISessionImplementor session, Object obj)
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
at Quiddita.Business.Statistics.Services.StatisticsBusinessService.<>c__DisplayClass1.b__0() in d:\Projects\CAT – Site Database\Source\Quiddita.Business.Statistics\Services\StatisticsBusinessService.cs:line 71
at NHibernate.Base.Transaction.With.Transaction(IsolationLevel level, Action transactional) in d:\Projects\CAT – Site Database\Source\NHibernate.Base\Transaction\With.Transaction.cs:line 54
at Quiddita.Business.Statistics.Services.StatisticsBusinessService.CreateNewUserSession(Nullable1 userId, String IPAddress) in d:\Projects\CAT – Site Database\Source\Quiddita.Business.Statistics\Services\StatisticsBusinessService.cs:line 74
at Quiddita.Aspects.Statistics.MethodBoundaryAspects.NewSessionAspectAttribute.OnSuccess(MethodExecutionArgs args) in d:\Projects\CAT – Site Database\Source\Quiddita.Aspects.Statistics\MethodBoundaryAspects\NewSessionAspectAttribute.cs:line 68
2018-05-07 00:24:31,056 WARN NHibernate.Util.ADOExceptionReporter - System.Data.SqlClient.SqlException (0x80131904): Violation of PRIMARY KEY constraint 'PK__tUserSes__3214EC07F91B0D0B'. Cannot insert duplicate key in object 'SiteUser.tUserSession'. The duplicate key value is (1).
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.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 System.Data.SqlClient.SqlCommandSet.ExecuteNonQuery()
at NHibernate.AdoNet.SqlClientBatchingBatcher.DoExecuteBatch(IDbCommand ps)
ClientConnectionId:a7af4119-1d67-4f69-ae91-fc556c97768f
Error Number:2627,State:1,Class:14
2018-05-07 00:24:31,068 ERROR NHibernate.Util.ADOExceptionReporter - Violation of PRIMARY KEY constraint 'PK__tUserSes__3214EC07F91B0D0B'. Cannot insert duplicate key in object 'SiteUser.tUserSession'. The duplicate key value is (1).
The statement has been terminated.
2018-05-07 00:24:31,068 ERROR NHibernate.Event.Default.AbstractFlushingEventListener - Could not synchronize database state with session
NHibernate.Exceptions.GenericADOException: could not execute batch command.[SQL: SQL not available] ---> System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK__tUserSes__3214EC07F91B0D0B'. Cannot insert duplicate key in object 'SiteUser.tUserSession'. The duplicate key value is (1).
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.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(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.SqlClient.SqlCommandSet.ExecuteNonQuery()
at NHibernate.AdoNet.SqlClientBatchingBatcher.DoExecuteBatch(IDbCommand ps)
--- End of inner exception stack trace ---
at NHibernate.AdoNet.SqlClientBatchingBatcher.DoExecuteBatch(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatchWithTiming(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatch()
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
2018-05-07 00:24:31,068 ERROR NHibernate.Base.Transaction.With - Transaction failed.
An this is part of the StatisticsBusinessService.cs:line 74
/// <summary>
/// Creates new <c>UserSession</c> and saves the object to database.
/// </summary>
/// <param name="userId">The database id of the<see cref="User"/> associated with the Session. If <c>null</c> then the anonymous user is in question.</param>
/// <param name="IPAddress">The IPAddress of the client machine the page was accessed from.</param>
/// <returns>The newly created <c>UserSession</c> object.</returns>
public UserSession CreateNewUserSession(long? userId, string IPAddress)
{
UserSession userSession = null;
With.Transaction(() =>
{
userSession = InitializeUserSession();
if (userId.HasValue)
userSession.User = _securityService.LoadUser(userId.Value, null);
userSession.IPAddress = IPAddress;
UnitOfWork.CurrentSession.SaveOrUpdate(userSession);
});
return userSession;
}
I discovered that in the hours prior to the problem appearing we were getting a bunch of brute force password guesses. Each of those was logged in a session table. The logins kept coming but we implemented a firewall to allow only a set of IP to login. So I think we haven't been breached.
Prior to the problem the Windows server wasn't accessed in weeks. The files haven't been changed, and the database hasn't been changed. The windows hasn't been updated. Basically nothing on the system changed, but the id counter was somehow reset. I checked the database, the id columns weren't set to identity (false), so I guess the auto-increment has been implemented in the app, rather than at the database level.
I have 0 experience with C#, SQL Server and the entire Windows ecosystem. I am at a complete loss of what is going on.
We use Windows Server 2012r2, SQL Server 2014 Express, IIS 8
Any clue will be much appreciated.
What a stack trace!
If I've understood correctly your autonumber seed just got reset.
Make a backup and try this:
SELECT MAX(tUserSession) FROM SiteUser
You'll got a number, let say 123456
then reseed your autonumber with the same value:
DBCC CHECKIDENT (SiteUser, RESEED, 123456)

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)

SQL Server (0x80131904): String or binary data would be truncated [duplicate]

This question already has answers here:
error, string or binary data would be truncated when trying to insert
(19 answers)
Closed 8 years ago.
I keep getting this error
ErrorSystem.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated. 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.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 workOrder.btnSubmit_Click(Object sender, EventArgs e) in h:\WebSite1\workOrder.aspx.cs:line 60 ClientConnectionId:2b010913-ba9f-4423-b6e1-2e9a038431ce
and googling tells me that a string input is too long to be processed by the database, but all of my fields are large enough and i cant figure this out,
here is my code:
<!--Removed-->
I get this error even when I leave every nullable field blank and only input 1 character for the rest of the items
Edit:
The Table:
<!--Removed-->
Edit:
asp code:
<!--Removed-->
Edit:
Removed all code for security,
This is error occurs when your column size is less than your text size.
For Example : In Database you have column " name varchar(10)" and the size of your data is greater than 10 . At this Situation error is occurred.
EX : If i enter "Siddharth Shukla" in name field than it will give error . so i have to change my column size from 10 to 20.

How to get local resources in the Controller

I'm trying to do this:
HttpContext.GetLocalResourceObject("~/Views/Shared/AnotherFolder/More/App_LocalResources/MyResourceFile.cshtml.resx", "myKey")
But I keep getting this error from within the controller:
The resource class for this page was not found. Please check if the resource file exists and try again.
That's if I wrap the call in a try block. Otherwise, the function is popped out of.
Directory structure, where Views is just right after the root folder:
I'm certain the path is correct as I just copied it from the resource file's properties window, but what could be wrong? Is the virtual path incorrect?
Here's the debug output:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Web.dll
System.Data.SqlClient.SqlException (0x80131904): Could not find stored procedure 'ELMAH_LogError'.
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.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.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Elmah.SqlErrorLog.Log(Error error)
at Elmah.ErrorLogModule.LogException(Exception e, HttpContext context)
This MSDN article states:
A local default resource file stored in the special App_LocalResources
folder is named according to the ASP.NET page. For example, if the
following code is used in a Default.aspx page, the resource file must
be named Default.aspx.resx.
You haven't said from where (or exactly how) you are calling:
HttpContext.GetLocalResourceObject("~/Views/Shared/AnotherFolder/More/App_LocalResources/MyResourceFile.cshtml.resx", "myKey")
Hence as the article suggests, if you are calling this method from within a file called "Default.aspx" (for example), rename the resource file to "Default.aspx.resx" and use this method call instead:
var resource = GetLocalResourceObject("myKey").ToString();
Note that I've assigned the result to "resource" as I assume that you are doing something similar in your real code, also note the need to cast the result to whatever type you are expecting.

Categories

Resources