AccessProviders working on WebDevelopment Server b

2019-08-01 21:42发布

问题:

I'm using the AccessProviders, to provide membership, roles, personalization and profiles, for my ASP.Net website instead of the built-in SQLServer Providers.

I'm using ASP.Net 2.0 on IIS7. Everything works fine on the ASP.Net Development Server, the whole module is working as it should, but when I switch it on the IIS7, it doesn't work, it gives the following error when someone tries to login:

Server Error in '/' Application.

AccessFile is not valid: D:\~thewholepath~\App_Data\ASPNetDB.mdb

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: 

[Exception: AccessFile is not valid: D:\~thewholepath~\App_Data\ASPNetDB.mdb]
   Samples.AccessProviders.AccessConnectionHelper.EnsureValidMdbFile(String fileName) +231
   Samples.AccessProviders.AccessConnectionHelper.BuildConnectionForFileName(String dbFileName) +496
   Samples.AccessProviders.AccessConnectionHelper.GetConnection(String dbFileName, Boolean revertImpersonation) +205
   Samples.AccessProviders.AccessMembershipProvider.ValidateUser(String username, String password) +182
   System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e) +75
   System.Web.UI.WebControls.Login.AttemptLogin() +152
   System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +124
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

Version Information: Microsoft .NET Framework Version:2.0.50727.4959; ASP.NET Version:2.0.50727.4955

I scourged the web for some answers, did get some pointers but they just don't seem to work for me. Also, a point of difference in all those solutions was that their module was not working on even the ASP.Net Development Server, but mine is working. So, that clears the ASPNetDB.mdb from any malice.

What I gather from this is that there must be some configuration error that I might be making in the web.config, so here are the relevant parts from the web.config:

<connectionStrings>
   <add name="AccessFileName" connectionString="~/App_Data/ASPNetDB.mdb" providerName="System.Data.OleDb" />
</connectionStrings>

<authentication mode="Forms">
      <forms loginUrl="admin-login.aspx" defaultUrl="index.aspx" />
</authentication>


<authentication mode="Forms">
  <forms loginUrl="admin-login.aspx" defaultUrl="index.aspx" />
</authentication>
<membership defaultProvider="AccessMembershipProvider" hashAlgorithmType="SHA1">
  <providers>
    <clear />
    <add name="AccessMembershipProvider" type="Samples.AccessProviders.AccessMembershipProvider, SampleAccessProviders" connectionStringName="AccessFileName" enablePasswordRetrieval="false" enablePasswordReset="false" requiresUniqueEmail="false" requiresQuestionAndAnswer="false" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="1" applicationName="fmobiles" hashAlgorithmType="SHA1" passwordFormat="Hashed" />
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="AccessRoleProvider" cacheRolesInCookie="true" cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
  <providers>
    <add name="AccessRoleProvider" type="Samples.AccessProviders.AccessRoleProvider, SampleAccessProviders" connectionStringName="AccessFileName" applicationName="fmobiles" />
  </providers>
</roleManager>
<profile enabled="true" defaultProvider="AccessProfileProvider">
  <providers>
    <add name="AccessProfileProvider" type="Samples.AccessProviders.AccessProfileProvider, SampleAccessProviders" connectionStringName="AccessFileName" applicationName="fmobiles" description="Stores and retrieves profile data from an ASP.NET_Access_Providers database." />
  </providers>
  <properties>
    <add name="FriendlyName" type="string" allowAnonymous="true" serializeAs="String" />
    <add name="Height" type="int" allowAnonymous="true" serializeAs="String" />
    <add name="Weight" type="int" allowAnonymous="true" serializeAs="Xml" />
  </properties>
</profile>
<anonymousIdentification enabled="false" cookieName=".ASPXANONYMOUS" cookieTimeout="100000" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="None" domain="" />
<webParts>
  <personalization defaultProvider="AccessPersonalizationProvider">
    <providers>
      <add name="AccessPersonalizationProvider" type="Samples.AccessProviders.AccessPersonalizationProvider, SampleAccessProviders" connectionStringName="AccessFileName" applicationName="fmobiles" />
    </providers>
  </personalization>
</webParts>

BIG UPDATE: I changed the function of the AccessConnectionHelper.cs Class to throw the actual error rather than a static error. Now, it tells me that The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. I searched regarding the error and it turns out that my machine and the IIS7 Server are on x64 architecture. The possible solution for that is to recompile the AccessProviders project for an x86 framework, i tried that but then this error throws up: Could not load file or assembly 'SampleAccessProviders' or one of its dependencies. An attempt was made to load a program with an incorrect format.

LATEST UPDATE: With the help of Mr.Kev, the cause of the error was narrowed down to setting Enable 32-bit applications to true for my website's application pool, the server guys did this setting and that error was gone. Now, there's a new problem, the ASPNetDB.mdb file which maintains the authentication/membership/roles data, is being read alright(I know this since when I put wrong credentials, the error is not an ASP.Net error), but the file cannot be written to(since when I put the correct credentials the AccessProviders module tries to write the logon information to the file), an error is thrown: "Operation Must Use An Updateable Query". I know that this is just a matter of providing the right permissions to the App_Data folder, but the server guys say that they've already given the appropriate permissions to the folder to allow write operation. So I'm now wondering that can this error be caused by anything other than insufficient write permissions or is it just a case of an incompetent server guy?

So, I'm still stuck with no luck.

That's pretty much it. Any help is deeply appreciated, thanks in advance.

回答1:

The problem is with your connection string:

<add name="AccessFileName" 
     connectionString="~/App_Data/ASPNetDB.mdb" 
     providerName="System.Data.OleDb" />

What you want is:

<add name="AccessFileName" 
     connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|ASPNetDB.mdb" 
     providerName="System.Data.OleDb" />

Update:

To solve the The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. problem, change the application pool that the site is running on to 32 bit mode. This is because that driver is 32 bit only.

If this is not possible then download and install the Microsoft Access Database Engine Redistributable 64 bit components:

Microsoft Access Database Engine 2010 Redistributable

Download and install: AccessDatabaseEngine_x64.exe

(These drivers may already be installed on your server)

Then change the connection string to:

<add name="AccessFileName" 
     connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|ASPNetDB.mdb" 
     providerName="System.Data.OleDb"/>


标签: asp.net iis-7