SqlMembershipProvider not compatible with this version - sql-server

I generated a script for my aspnet Database, now when I try to use the database it gives an error
The 'System.Web.Security.SqlMembershipProvider' requires a
database schema compatible with schema version '1'. However,
the current database schema is not compatible with this version. You
may need to either install a compatible schema with aspnet_regsql.exe
(available in the framework installation directory), or upgrade the
provider to a newer version.
What options do I really have to solve this problem?
Do I need to run aspnet_regsql.exe or is there a way to get around this error besides having to go with this option as the error suggests?
My web.config file looks like this:
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<membership defaultProvider="SqlProvider">
<providers>
<clear/>
<add name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="CPMS_DB"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="3"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="3"
applicationName="/"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="ApplicationServices"
applicationName="/"/>
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices"
applicationName="/"
name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/"
name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>

I would use the aspnet_regsql.exe to create a new/blank database.
Then you could use this:
http://granadacoder.wordpress.com/2007/11/29/membershipprovider-helper-to-transfer-data/
It will "create tsql code" so you can move all your data into your blank database.

I had similar error, 'simple' solutions like closing the project and re-opening, rebuilding, resolves the error. that's if you're sure you did everything correctly

Related

How do I not use the App_Data folder in an ASP MVC4 application?

Everything works fine locally, but when I publish, I get the error below. I am using forms authentication, but I define my own connection string to a non-sqlexpress database. I don't understand why my application would need access to create a database (or anything else) in the App_Data folder, because my database is not/will not be there. Any help is appreciated.
Connection String:
<connectionStrings>
<add name="DataContext" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog={my db};Integrated Security=SSPI;MultipleActiveResultSets=True" />
</connectionStrings>
Error:
Access denied creating App_Data subdirectory
Description: For security reasons, the identity 'IIS APPPOOL\ASP.NET v4.0' (under which this web application is running), does not have permissions to create the App_Data subdirectory within the application root directory. ASP.NET stores the Microsoft SQL Express Database file used for services such as Membership and Profile in the App_Data subdirectory of your application.
Edit: It tells me how to fix the error by adding the App_Data folder and providing the correct permissions, but I don't understand why I need this folder at all, and if I can avoid changing permissions, I'd like to.
I think I finally figured out how to stop ASP from trying to create the ASPNETDB.MDF database in the App_Data folder automatically. What I found worked combined two existing stackoverflow answers:
Disable SQL Membership Provider (ASP.Net Forms Authentication)
It turns out that, on the production machine, the SQL membership provider was defined in machine.config. I don't think the ops team changed anything from the default Windows 2008 install, so that's probably generally the case for that platform.
To remove references to any SQL providers defined at a higher level include the following in your web.config
<membership>
<providers>
<clear />
</providers>
</membership>
<roleManager enabled="false">
<providers>
<clear />
</providers>
</roleManager>
<profile>
<providers>
<clear />
</providers>
</profile>
AspNet Role provider kicking in and it shouldn't be
To disable 'SimpleMembership' you can add app setting enableSimpleMembership with value="false" (web.config). This will prevent webmatrix from reconfiguring RoleManager.
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="enableSimpleMembership" value="false" />
</appSettings>
</configuration>
Check if the 'connectionStringName' property of the 'membership' node in your web.config is set to your connectionstring, like this:
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="DataContext"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
*<membership>
<providers>
<clear />
</providers>
</membership>
<roleManager enabled="false">
<providers>
<clear />
</providers>
</roleManager>
<profile>
<providers>
<clear />
</providers>
</profile>*

Getting error "The user instance login flag is not supported on this version of SQL Server." but not using this flag

I recently upgraded a SQL Server Express database I was using locally to SQL Server 2012 Developer. I started getting this error. A quick search pulls up tons of posts where the answer seems to be to remove User Instance=True; from your connection strings.
I checked and none of my connection strings have this flag. I tried searching the entire solution for "user instance" just to make double sure and it doesn't show up anywhere. Doubly weird is that I don't get this error right away. The first couple calls to the database work...
Has anyone else had a similar experience?
Here is the exact code that is causing my error:
public class BetterAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
{
var roleList = Roles.Split(',');
//if the user is in one of the roles in the list
foreach (string r in roleList)
{
if (filterContext.HttpContext.User.Identity.IsAuthenticated)
{
//The error is consistently thrown here the second time this line
//executes...
if (filterContext.HttpContext.User.IsInRole(r.Trim()))
{
Here are the config sections I thought were relevant:
<connectionStrings>
<add name="BioSphereContext"
providerName="System.Data.SqlClient"
connectionString="Server=fake;Database=fake;User ID=fake;Password=fake;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=true;" />
</connectionStrings>
.
.
.
<sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="15">
<providers>
<add name="DefaultSessionProvider"
type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</sessionState>
.
.
.
<entityFramework>
<defaultConnectionFactory
type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Some more details about my project in case it helps...
VS 2012
Entity Framework 5
Azure SDK 2.0
ASP.NET MVC 3
.net 4.5
This code uses ASP.NET Membership Roles Provider
if (filterContext.HttpContext.User.IsInRole(r.Trim()))
The machine.config shows
<roleManager>
<providers>
<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</roleManager>
Pointing to "LocalSqlServer" in the same file
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
There is the User Instance.
TODO: Configure your roleManager to use either another roles provider or the AspNetSqlRoleProvider to use a different connection string.
same goes for session (What is DefaultConnection? i don't see a connection string named like this), membership and profile.
So try:
<sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="15">
<providers>
<add name="DefaultSessionProvider"
type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="BioSphereContext" applicationName="/" />
</providers>
</sessionState>
Not sure what was wrong, but I deleted and re-cloned my git repository. Error went away.... never getting that day back... lol. I'll leave the post in case any of this is helpful to others.

Silveright config error stopped

Server Error in '/' Application.
I have just started to publish the app to IIS server but it is failing, any ideas on this how to solve?
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. (C:\PBM_Test\web.config line 15)
Source Error:
Line 13:
Line 14:
Line 15: Line 16:
Line 17:
Source File: C:\PBM_Test\web.config Line: 15
this is the web.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, `enter code here`System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</modules>
<validation validateIntegratedModeConfiguration
="false" />
</system.webServer>
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="PBMEntities" connectionString="metadata=res://*/ModelPBM.csdl|res://*/ModelPBM.ssdl|res://*/ModelPBM.msl;provider=System.Data.SqlClient;provider connection string="data source=SRVORDERS;initial catalog=PBM;user id=OK;password=OK1;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
see http://forums.silverlight.net/t/180719.aspx/1
and http://community.discountasp.net/showthread.php?t=10296 for info
The above threads describe how you have to make sure that your web application has a copy of this file available.
If you are using a server you can install software to, the best solution is to make sure that the server has both the latest version of .net and RIA services installed (Both may be separate installations) (EDIT - make sure all the packages that alfonso list are installed.)
If you don't have access to install software on the server, the other solution is to make sure that ServiceMode.DomainServices.Hosting 4.0 is copied to the BIN folder during deployment of your ASP solution - set the file properties to Local Copy / Only if Newer
Make sure you have installed all of these packages on the server:
Silverlight4 Tools
Silverlight SDK
RiaServicesToolkit
RiaServices
Hope it helps!

How do I make DbProviderFactories for SQL Server

I get the same error as the guy in http://sqlite.phxsoftware.com/forums/t/239.aspx but the thing is he uses SQLite and I use SQL Server 2008 and adding that code don't change anything for me I still get the
Unable to find the requested .Net Framework Data Provider. It may not be installed.
I am trying to get the MVC 3 account to work with my websites database and changed the connectionstring to my own in web.config
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="madsskipper_dk_dbEntities" applicationName="/"/>
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="madsskipper_dk_dbEntities" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="madsskipper_dk_dbEntities" applicationName="/"/>
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="madsskipper_dk_dbEntities" applicationName="/"/>
</providers>
</sessionState>
From the name of your connection string, it seems as if you may have specified an Entity Framework connection string.
If so, you need to add a SqlClient connection string, and change your providers to use the SqlClient connection string.

How to connect to DB on SERVER for Asp.Net membership?

I've just upload my ASPNETDB.mdf using "Generate Scripts" into server.
The problem is, I don't know how can I connect to it for my Membership.(e.g LogIn Controls)
where is the ConnectionString?
update the Data Source tag in web config
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<<PATH Goes Here>>;Persist Security Info=False;
The connectionstring is in the web.config file.
Modify the web.config file for your application to redefine the LocalSqlServer connection string to point to the database.
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="server=.;database=aspnetdb;
integrated security=sspi;"/>
</connectionStrings>
If your Membership provider is not pointing to "LocalSqlServer", then you can modify that in the web.config as well.
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, ..."
connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
/>
</providers>
</membership>

Resources