System.Data.OleDb.OleDbException: Unspecified error - asp.net

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\

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.

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.

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 add custom sign in page for FBA application

I have configured FBA for my web application which is working fine with default sign in pages. So i wanted to create custonm sign in page for that application. For that i have created a custom sign in page. but when i entered credential it gives me an error as below.
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.]
LdapContosoAuthentication.Layouts.LdapContosoAuthentication.LoginCustmCntrlPage.Button1_Click(Object
sender, EventArgs e) +193
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +114
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +139
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +28
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+2980
Can anyone tell me how can i solved that error?
Put your custom page in layout folder and make below changes. So you can open your custom login page:
<authentication mode="Forms">
<forms loginUrl="/_layouts/CustomLogin.aspx" />
</authentication>
Have you made any change in delegate control (login control) of login.aspx page?

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.

Resources