Execution of the command requires an open and available connection. The connection's current state is broken - asp.net

Serious problem with entity framework & sql server 2008, please help!!
System works well locally but during load test at production server we have following error for more then 10 users.
After get this error user can not logged in anymore.
Server Error in '/' Application.
Execution of the command requires an open and available connection. The connection's current state is broken.
Here is SQL Server Log
3005
An unhandled exception has occurred.
9/13/2011 3:41:14 AM
9/13/2011 7:41:14 AM
73b3f335f4de45fa8c4ef2f22809300b
4911
482
0
/LM/W3SVC/14/ROOT-3-129603711416579333
Full
/
E:\WebSites\Medtrack2.0\
COLO-VDEV01
15864
w3wp.exe
NT AUTHORITY\NETWORK SERVICE
InvalidOperationException
Execution of the command requires an open and available connection. The connection's current state is broken. at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) at Dashboard.Page_Load(Object sender, EventArgs e) at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
http://38.127.112.89:9010/Dashboard.aspx
/Dashboard.aspx
119.148.4.83
JMiranda
True
Forms
NT AUTHORITY\NETWORK SERVICE
11
NT AUTHORITY\NETWORK SERVICE
False
at System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) at Dashboard.Page_Load(Object sender, EventArgs e) at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
have any idea?

See if the answer to this similar question can help you:
EF recovery from invalidoperationexception caused by server being down
or this one:
Exception: Execution of the command requires an open and available connection. The connection's current state is broken.

How are you storing the ObjectContext? From an EF perspective, you have to make sure each user gets a unique reference to the ObjectContext. To do that, I share the ObjectContext by storing it in the HttpContext.Current.Items collection. See this for more information on the Items collection: http://abhijitjana.net/2011/01/14/when-we-can-use-httpcontext-current-items-to-stores-data-in-asp-net/

Related

Stored procedure found on localhost but can't be found when published

I have a stored proc on a server. The same server is used in both local development and the remote Dev server I have.
The site functions fine when I run it in debug on my local machine. When I publish it returns:
The stored procedure 'vts_spUserGetUserIdFromUserName' doesn't exist.
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.InvalidOperationException: The stored
procedure 'vts_spUserGetUserIdFromUserName' doesn't exist.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The stored procedure
'vts_spUserGetUserIdFromUserName' doesn't exist.]
System.Data.SqlClient.SqlCommand.DeriveParameters() +3962
System.Data.SqlClient.SqlCommandBuilder.DeriveParameters(SqlCommand
command) +127
Microsoft.Practices.EnterpriseLibrary.Data.Database.DiscoverParameters(DbCommand
command) +154
Microsoft.Practices.EnterpriseLibrary.Data.ParameterCache.SetParameters(DbCommand
command, Database database) +114
Microsoft.Practices.EnterpriseLibrary.Data.Database.AssignParameters(DbCommand
command, Object[] parameterValues) +42
Microsoft.Practices.EnterpriseLibrary.Data.Database.GetStoredProcCommand(String
storedProcedureName, Object[] parameterValues) +70
Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteScalar(String
storedProcedureName, Object[] parameterValues) +38
Votations.NSurvey.SQLServerDAL.User.GetUserByIdFromUserName(String
userName) +226
Votations.NSurvey.WebAdmin.NSurveyAdmin.UserControls.LoginBox.ValidateCredentialsButton_Click(Object
sender, EventArgs e) +168
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11761917
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +150 System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+6016
The stored proc is definitely there. I have KDiff'd the two web.config files and there are no differences.
The only issue I can think of is that on the server it is in a Web Application as a sub application of another root site. Could that be the reason. It is inheriting database connection strings from the other application? If so is there any way I can stop that behavior?
Check the schema under which the Stored Procedure is created.
I might be possible that the Stored Procedure is created under your account, that is why when you are running it on local machine its able to find the SP and not when its running under some other account on sever.

WF 4.0 can't get to resume workflow on the staging/production environment

I have developed various registeration workflows using WF4.0. Each work flow has various bookmarks. I am using the registeration wf for an asp.net application.
I tested the asp.net application locally and it is working fine( Starting WF, Persisting to db and resuming bookmarks). When I try to test it on the staging server, everything goes messy. I can no longer resume wfs and I get an error message :
System.Runtime.DurableInstancing.InstancePersistenceCommandException
was unhandled by user code Message=The execution of the
InstancePersistenceCommand named
{urn:schemas-microsoft-com:System.Activities.Persistence/command}LoadWorkflow
was interrupted by an error. Source=System.Runtime.DurableInstancing
StackTrace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.Runtime.DurableInstancing.InstancePersistenceContext.OuterExecute(InstanceHandle
initialInstanceHandle, InstancePersistenceCommand command, Transaction
transaction, TimeSpan timeout)
at System.Runtime.DurableInstancing.InstanceStore.Execute(InstanceHandle
handle, InstancePersistenceCommand command, TimeSpan timeout)
at System.Activities.WorkflowApplication.PersistenceManager.Load(TimeSpan
timeout)
at System.Activities.WorkflowApplication.LoadCore(TimeSpan timeout, Boolean loadAny)
at System.Activities.WorkflowApplication.Load(Guid instanceId, TimeSpan timeout)
at System.Activities.WorkflowApplication.Load(Guid instanceId)
at CEO_StartUpCEORegisterationTest.LoadInstance(Guid wfInstanceId) in c:\Users\Kunoichi\Documents\Visual Studio
2010\Projects\CMERegistrationSystem\RegistrationPortal\CEO\StartUpCEORegisterationTest.aspx.cs:line
64
at CEO_StartUpCEORegisterationTest.Page_Load(Object sender, EventArgs e) in c:\Users\Kunoichi\Documents\Visual Studio
2010\Projects\CMERegistrationSystem\RegistrationPortal\CEO\StartUpCEORegisterationTest.aspx.cs:line
44
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.Data.SqlClient.SqlException
Message=Index 'NCIX_KeysTable_SurrogateInstanceId' on table 'KeysTable' (specified in the FROM clause) does not exist.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=211
Number=308
Procedure=LoadInstance
Server=
State=1
StackTrace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.Activities.DurableInstancing.SqlWorkflowInstanceStoreAsyncResult.SqlCommandAsyncResultCallback(IAsyncResult
result)
I know that this is quite verbose. But I have been banging my head against the wall for more than a week. I did search and all I came to know was to work on ms dtc. I enabled it on the staging server , I installed application server on the staging server and I am still getting the same error. I would appreciate if anyone could help with the problem. Thanks in advance :)
Who created the persistence store being used on the staging server? What schema was used to create it? Look for differences between the scripts used locally and in production.

Web App works on localhost but fails on remote connection

We have a new ASP.NET web application we are deploying that uses a separate DLL which we also built which in turn interrogates the Active Directory for simple user and group membership information. The server is Windows Server 2003.
The application works fine if I RDP to the server and browse it under localhost.
The application throws the following error when I browse to it from a separate PC. It also throws the same error if I browse to it from the RDP session on the server, but browse it under the server name.
Is this a code-access security issue? Other ideas?
Exception Details: System.Runtime.InteropServices.COMException: An operations error occurred.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[COMException (0x80072020): An operations error occurred.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +420085
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.get_Name() +32
USM.UsmAD.get_DomainName() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\Active Directory Search\USMAD\USMAD\UsmAD.cs:60
USM.UsmAD.Get_UserGroupNames(String username) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\Active Directory Search\USMAD\USMAD\UsmAD.cs:190
AdminWeb.CheckAccessDAL.GetGroupNames() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\USMDAL\CheckAccessDAL.cs:28
AdminWeb.CheckAccessDAL.SetMenuAccess(Menu mnuUSMAdmin) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\USMDAL\CheckAccessDAL.cs:89
AdminWeb.SiteMaster.TrimMainMenus() in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\AdminWeb\Site.Master.cs:50
AdminWeb.SiteMaster.Page_Load(Object sender, EventArgs e) in C:\DevWork\Repo_CP\UnifiedSecurity\BRANCHES\LoginVsGUID\Applications\AdminWeb\AdminWeb\Site.Master.cs:17
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
sounds like a perms issue on the dll
try allowing IUSR access to this file....
You will probably need to run your app pool under an domain level identity that has permission to access the resources it needs to talk to Active Directory.
Specify an Identity for an Application Pool (IIS 7)
Configuring Application Pool Identity with IIS 6.0 (IIS 6.0)
Here is an article if you need to do this at runtime:
How To: Use Impersonation and Delegation in ASP.NET 2.0
I also encourage you to implement an UnhandledException handler to log these run-time errors.

How to trace Error on a Deployed ASP.Net Application?

VS 2008 / ASP.Net
I have a deployed a ASP.Net Web Application on Windows 2003 Server. For some reasons, it throws an error.
Application works great on my local computer. Either from source code or hosted on my local machine (Windows XP).
How to trace error on a deployed ASP.Net Web Application ?
Error :
Object reference not set to an instance of an object. 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.NullReferenceException: Object reference not
set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
_Default.ExportRx30ToSalisburyAccessDB() +351
_Default.Button1_Click(Object sender, EventArgs e) +5
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Source code : Which i am facing this error ..
try
{
Access.Application access1 = new Access.Application();
// Open the Access database for exclusive access
string sSalisburyAccessDB = Server.MapPath("~/App_Data/Salisbury.mdb");
access1.OpenCurrentDatabase(sSalisburyAccessDB, true, null);
// Drop the existing table data
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "drug");
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "patplan");
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "plans");
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "price");
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "rx");
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "patient");
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "plntrak");
// Run the saved import
access1.DoCmd.RunSavedImportExport("SalisburyODBC");
// Close the database
access1.CloseCurrentDatabase();
// Quit MS Access
access1.Quit(Access.AcQuitOption.acQuitSaveAll);
Response.Write("successful");
}
catch (Exception ex)
{
Response.Write(ex.InnerException.Message);
}
Try running your app in IIS Express instead of Cassini (the built-in Visual Studio development web server). They behave differently and you might have a better shot at recreating the issue in your development environment. IIS Express runs just like real IIS so there are fewer surprises when you deploy your application.
Try deploying the application in debug mode, which should give you a specific line number and code file where the error occurred. Simply place this in your web.config file:
<configuration>
<system.web>
<compilation debug="true">
</system.web>
</configuration>
However, in general, you do not want to deploy to final production in debug mode. Instead, make use of try...catch blocks and good status/exception logging in your application to track down problems.
The easiest way to find where such errors occur is to split your methods down to just do one thing per method. For example, instead of adding a comment that say // Run the saved import, make a method of it RunTheSavedImport() and you will much easier be able to detect in which part of the code the error occurs directly from the stack trace.
What I can see , if the code you have provided is the full ExportRx30ToSalisburyAccessDB-method, the most probable causes for this error is that either DoCmd, AcQuitOption or AcObjectType of some reason are null. Since the stack do not enter Application it can only be caused by objects inside this method.
[ObjectDisposedException: Cannot access a closed resource set.] System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString) +1657 System.Resources.RuntimeResourceSet.GetString(String key, Boolean ignoreCase) +12 System.Resources.ResourceManager.GetString(String name, CultureInfo culture) +78 SourceCode.Workspace.OOBReports.ReportList.CreateChildControls() +347 System.Web.UI.Control.EnsureChildControls() +146 System.Web.UI.Control.PreRenderRecursiveInternal() +61 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394
simply reset your IIS server.

NullReferenceException in Page_Load

I have developed my project in asp.net 3.5. It works fine in localhost, when i published in the web sometimes its working fine but sometimes i am getting the following error. I think some error while conecting to the server but dont know exactly. Please help me to do it fine.
Server Error in '/' Application.
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] Result.Page_Load(Object sender, EventArgs e) +128 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Enable debugging in your web.config file (Debug="True") and turn RemoteErrors="On". This will provide a much more detailed error message so that you can find what is throwing the NullReferenceException. Once solved, remember to reset these configurations.
Check the code inside your Page_Load method, its throwing a null refernce exception
HTTP Request pipeline is giving the issue here not the page.
you need to check and trace HTTPContext here

Resources