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

北城以北 提交于 2019-12-12 04:37:55

问题


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

回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/17262042/getting-error-the-user-instance-login-flag-is-not-supported-on-this-version-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!