简体   繁体   中英

Usermanager find async error

i'm trying to authenticate on a .net api with Oauth token and i get the following error when i'm accessing the /auth route:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.

All day long i tried to fix this but with no success. I'll be glad if i get some help.

So, this is the code where i get the error:

   var allowedOrigin = "*";

        context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

        var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();
        AspnetUserService service = new AspnetUserService();


        ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password); <---- here, when i send via Postman, i'll wait ~2 minutes to get a response. When the response arrived, this above error appears.

What is weird is that i tried to make a new registration on DB with identity and it worked. I tried to get some values from DB, worked too.

I run a SQL server locally, these are my two connection strings:

<add name="AuthContext" connectionString="Server=localhost;Initial Catalog=SeeMe2;User ID=SeeMe2;Password=password;" providerName="System.Data.SqlClient" />
<add name="SeeMe2Entities" connectionString="metadata=res://*/Context.SeeMe.csdl|res://*/Context.SeeMe.ssdl|res://*/Context.SeeMe.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=SeeMe2;persist security info=True;user id=SeeMe2;password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I tried to debug the code, all the variables seem to have the right values. Any suggestions? Thanks a lot !

You have a trouble with your SQL connectin string.

Your connection string is:

<add name="AuthContext" connectionString="localhost;Initial Catalog=SeeMe2;User ID=SeeMe2;Password=password;" providerName="System.Data.SqlClient" />

There you have not Server and Database attribute.

The correct connection string is:

<add name="AuthContext" connectionString="Server=localhost;Database=SeeMe2;User ID=SeeMe2;Password=password;" providerName="System.Data.SqlClient" />

More information about connection string is here .

Also check your SeeMe2Entities connection string.

As I can see it has incorrect values on connection section (you have missed Server and Database also).

At the AuthContext connection string Server attribute missing. it should be like this.

<add name="AuthContext" connectionString="Server=localhost;Initial Catalog=SeeMe2;User ID=SeeMe2;Password=password;" providerName="System.Data.SqlClient" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM