Stored procedure found on localhost but can't be found when published - asp.net

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.

Related

ASP.NET - Accessing Active Directory from code behind page

I have made a web application, which reads/writes from/to Active Directory. In my web.config file there is
<identity impersonate="true"/>
and
<authentication mode="Windows"/>
When I display
System.Web.HttpContext.Current.User.Identity.Name
in some label, it shows mydomain\myusername, so I think impersonation works.
Now to the question. When I access the application on the server, where the IIS web server is running, everything works great. But when I access the web application from a remote PC, I get an exception (the label still shows "mydomain\myusername").
I have traced the problem down. In the code behind when I call
Forest currentForest = Forest.GetCurrentForest();
the variable currentForest knows its currentForest.Name, currentForest.RootDomain or currentForest.ForestMode, but any call to currentForest.Domains, currentForest.Sites or currentForest.GlobalCatalogs results in
System.DirectoryServices.ActiveDirectory.ActiveDirectoryOperationException.
Now I'm lost and don't know what to debug further. The account I'm using is member of Enterprise Admins (multi-domain forest). I have tried it on two different servers with different IIS versions (IIS 7.5 and IIS 6.0) with no luck.
And the thrown exception isn't of much help:
Exception Details: System.DirectoryServices.DirectoryServicesCOMException: 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:
DirectoryServicesCOMException (0x80072020): An operations error occurred.
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +557
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_AdsObject() +42
System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) +98
System.DirectoryServices.ActiveDirectory.ADSearcher.FindAll() +46
System.DirectoryServices.ActiveDirectory.Forest.GetDomains() +543
[ActiveDirectoryOperationException: An operations error occurred.]
System.DirectoryServices.ActiveDirectory.Forest.GetDomains() +512484
System.DirectoryServices.ActiveDirectory.Forest.get_Domains() +44
myWebApp.ASPpage.Button_Click(Object sender, EventArgs e) in C:\Documents and Settings\myUser\documents\visual studio\Projects\MyWebApp\MyWebApp\ASPPage.aspx.cs:158
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
EDIT: If it is not obvious, I want to use currentForest.Domains to search the whole forest (all domains) for a user given by UPN name.
I found the answer to my question in one of "Related questions" on this page. The answer was in this topic: Why does DirectoryServicesCOMException occur querying Active Directory from a machine other than the web server?
I found, that it was exactly my case. After reading the suggested Microsoft article, I learned, that impersonating works only for local resources on the IIS server. To access network resources (SQL, Active Directory), I have to set "Trust this computer for delegation" in the computer object in Active Directory.
It was because the IIS always authenticate therefore System.Web.HttpContext.Current.User.Identity.Name showsmydomain\myusername; to verify that the impersonation works you could use:
System.Security.Principal.WindowsIdentity.GetCurrent().Name, also the System.Security.Principal.WindowsIdentity.GetCurrent(true) returns null when it is not impersonating.

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.

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.

System.Data.OleDb.OleDbException: Unspecified error

I'm Totally new in ASP.net and currently working on a CRM application. This project uses .mdb files as backend but I am getting the following runtime error:
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.Data.OleDb.OleDbException:
Unspecified error
Stack Trace:
[OleDbException (0x80004005):
Unspecified error]
EmployeeManager.isUser(String strUID,
String strPswd) in
d:\hosting\nitindia\App_Code\EmployeeManager.vb:481
Employees.BtnSubmit_Click(Object
sender, EventArgs e) in
d:\hosting\nitindia\Employees.aspx.vb:35
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
The above error occurs only when we upload these pages & test online. When running on localhost the error is not being raised.
What is the cause of this issue, and solution?
System.Data.OleDb.OleDbException: Unspecified error
This error mostly belongs to permission error, for this error we have mutiple solutions as per situation
Put the impersonate=false in web.config file.
If you want to put the impersonate = true in that case you need to provide the read/write permission to impersonate user on "C:\Documents and Settings\server name\ASPNET" folder or through process monitor utility you can check which file don't have sufficient permission.
If you have windows server 2008 then you will not found the ASPNET folder and still want impersonate=true then you need to change the configuration in IIS 7.5/7.0.
Go to IIS -> select your application pool -> Advanced Setting -> Process Model ->Identity=ApplicationPoolIdentity
Go to IIS -> select your application pool -> Advanced Setting -> Load User Profile = False
See here for more details.
Both of these conditions may cause this (rather unhelpfully named) error to occur:
The ASPNET account not having permissions to open the file.
The database file is locked by another user.
for answer finders :
try to look into https://learn.microsoft.com/en-us/iis/application-frameworks/running-classic-asp-applications-on-iis-7-and-iis-8/using-classic-asp-with-microsoft-access-databases-on-iis#using-process-monitor-to-gather-more-information and set Permissions on the Temporary Folders
PS in my case it was impersonate user who does not have access to current user temp folder C:\Users\`Username`\AppData\Local\Temp\

'License expired' error when dynamically generating Excel docs in ASP.NET

Anyone familiar with error below? When I run my webapp to generate a dynamic excel doc from my local machine it works fine but when the same piece of code is invoked on the server I get the below error. It seems like it's a permissions issues since it works on my machine but not the server but I don't know where to start in order to pinpoint the problem. Any guidance/help is greatly appreciated!
Server Error in '/' Application.
--------------------------------------------------------------------------------
This command is unavailable because the license to use this application has expired.
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.Runtime.InteropServices.COMException: This command is unavailable because the license to use this application has expired.
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 (0x800a03ec): This command is unavailable because the license to use this application has expired.]
Microsoft.Office.Interop.Excel.Workbooks.Add(Object Template) +0
PaymentsReport.Page_Load(Object sender, EventArgs e) +70
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Office/Excel is installed on the server and I can open/save excel docs on the server. Could it be the version of excel on the server vs. my local machine? If so how can I make sure I have the latest on the server?
Apart from being installed, you need to make sure the application is activated on the server:
http://support.microsoft.com/kb/294973
Has details on how to do this.
Using Office Interop requires that the Office components you're using actually be installed on the server.
I'm gonna take a WAG and say that you just can't slap any old copy of Office on a server and let multiple users access it via your website. You need to look at the licensing restrictions for using MS office in a server environment.
Do you have a licensed, activated copy of Excel on the server? It probably works on your local machine because you have Office/Excel installed locally.

Resources