Using PostgreSQL database for asp.net membership

Using PostgreSQL database for asp.net membership

Postby Uhanalainen » Wed 23 Sep 2015 11:10

I want to migrate our existing user database to postgreSql. But first, I thought it would be a good idea to try to get it working with an empty database, before starting the migration work. However, I ran into some problems and have no idea why, or what I have to do to fix them. I'm using Visual Studio 2012.

I started a new project (ASP.NET MVC 4 Web Application -> Internet Application) with .NET Framework 4 (also tried this with .Net FW 4.5).

Then, I added the references to the following files as stated in the tutorial
Devart.Data
Devart.Data.PostgreSql
Devart.Data.PostgreSql.Web

Here's my web.config

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="host=localhost;user id=postgres;password=abc123!" providerName="Devart.Data.PostgreSql" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <membership defaultProvider="PgSqlExtendedMembershipProvider">
      <providers>
        <remove name="PgSqlExtendedMembershipProvider"/>
        <add name="PgSqlExtendedMembershipProvider" type="Devart.Data.PostgreSql.Web.Providers.PgSqlExtendedMembershipProvider,
      Devart.Data.PostgreSql.Web, Version=7.4.492.4, Culture=neutral, PublicKeyToken=09af7300eec23701"
          description="dotConnect for PostgreSQL extended membership provider" connectionStringName="DefaultConnection" />
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="PgSqlExtendedRoleProvider">
      <providers>
        <remove name="PgSqlExtendedRoleProvider"/>
        <add name="PgSqlExtendedRoleProvider" type="Devart.Data.PostgreSql.Web.Providers.PgSqlExtendedRoleProvider,
        Devart.Data.PostgreSql.Web, Version=7.4.492.4, Culture=neutral, PublicKeyToken=09af7300eec23701"
            description="dotConnect for PostgreSQL extended role provider" connectionStringName="DefaultConnection" />
      </providers>
    </roleManager>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers></system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
   
  </entityFramework>
</configuration>


Lastly, I added this using statement in InitializeSimpleMembershipAttributes.cs in the Filters folder:
using Devart.Common.Web;
And I deleted the line
using WebMatrix.Webdata;

That's all there's to it, at least according to the tutorial on site, but when I run it, and click on register, I get this error:

"The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)":null

What did I do wrong?
Uhanalainen
 
Posts: 6
Joined: Wed 23 Sep 2015 10:56

Re: Using PostgreSQL database for asp.net membership

Postby Pinturiccio » Wed 23 Sep 2015 14:00

We could not reproduce the issue. In our environment everything works if we create a new ASP.NET MVC 4 Web Application -> Internet Application and follow the tutorial. Or even if we use your web.config (only the connection string is changed) the application still works.

Please try reinstalling dotConnect for PostgreSQL in the following way:
1. Uninstall dotConnect for PosgreSQL (if it is currently installed);
2. make sure that there are no Devart.* and policy.*.Devart.* files in the following folders:
* \Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Devart\
* GAC 2.0 (\Windows\assembly\) and GAC 4.0 (\Windows\Microsoft.NET\assembly\)
* \Program Files (x86)\Devart\
* \Program Files (x86)\Common Files\Devart\
* \Documents and Settings\All Users\Devart\EntityDeveloper\ (clear the folder)
* \Documents and Settings\All Users\Devart\dotConnect\ (clear the folder)

When you open the folder \Windows\assembly\ with Windows Explorer, a special shell extension is used to display this folder. To get to this directory, you should use Windows Explorer with the GAC shell extension turned off. The GAC shell extension connects to Explorer using the Desktop.ini file located in the assembly folder. Rename the Desktop.ini file to display the content of the assembly folder like content of any other folder. For this, run the following three commands in Command Prompt:
* Go to the GAC folder:
cd %windir%\assembly
* Remove the system and hidden attributes for the Desktop.ini file:
attrib –s –h desktop.ini
* Rename the file to disable the shell extension
ren Desktop.ini Desktop.ini.disabled

After this, use Explorer to go to the %windir%\assembly\GAC_MSIL\ folder and delete all folders with the names containing Devart.

Finally, rename the Desktop.ini.disabled file back to Desktop.ini.

3. Clean up the registry from the rest of Devart records. Navigate to the root of the registry and search for the word Devart. Delete all the nodes found.

4. Install dotConnect for PostgreSQL.
4.1. Run the installation 'As Administrator';
4.2. Make sure you have closed Visual Studio prior to performing the installation;
4.3. Make sure you use the full installation with such feature as "Support for ADO.NET Entity Framework" and "ASP.NET Web Providers".

If the error still persists after this, create and send us a complete small test project for reproducing the issue. Please also tell us your Operating system version and edition as well as the Service Pack version.
Pinturiccio
Devart Team
 
Posts: 2020
Joined: Wed 02 Nov 2011 09:44

Re: Using PostgreSQL database for asp.net membership

Postby Uhanalainen » Mon 28 Sep 2015 07:11

Hi,

thanks for the fast answer. I did a complete reinstall of the dotconnect driver today, as per the instructions, but I still cannot get it working for unknown reasons. The error is exactly the same as before. With debugging, I pinpointed it to the following line in InitializeSimpleMembershipAttribute.cs:

if (!context.Database.Exists())

After that line, it catches the exception. And it doesn't matter even if I create the database beforehand in pgAdmin, it still will catch an error right at that point.

Mind you, I've got other projects working fine with postgres, and the dotconnect model builder support is great but there's really no point in migrating to postgres if we still have to use sql server for user support.

Here's my computer specs. it's a Lenovo W530:

Intel Core i7-3630QM @ 2.40GHz
32GB RAM
Windows 10 Pro
Uhanalainen
 
Posts: 6
Joined: Wed 23 Sep 2015 10:56

Re: Using PostgreSQL database for asp.net membership

Postby Pinturiccio » Mon 28 Sep 2015 16:22

We could not reproduce the issue. Please provide the message and stack trace of the exception and all inner exceptions.
Also create and send us a small test project which reproduces the issue.
Pinturiccio
Devart Team
 
Posts: 2020
Joined: Wed 02 Nov 2011 09:44

Re: Using PostgreSQL database for asp.net membership

Postby Uhanalainen » Tue 29 Sep 2015 08:39

Hello again,

I tested the driver in a fresh environment like my own, using VirtualBox and everything worked like it's supposed to there, so I guess something was wrong with my setup on the laptop. Anyway, I reset the laptop to factory settings and now everything seems to work fine.

Thanks Pinturiccio for your help :)
Uhanalainen
 
Posts: 6
Joined: Wed 23 Sep 2015 10:56


Return to dotConnect for PostgreSQL