.net 4.0 Calling Membership validateuser method from another project in same solution throw null ex
I have a webservice project and a web project in the same solution.
The web project implements a membershipprovider.
I want to be able to authenticate user via the webservice project but when i call this method in the webproject:
开发者_如何学Gopublic static bool AuthUser(string userName, string password)
{
return Membership.ValidateUser(userName, password);
}
I get this inner ex. "Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed."
Calling the method from the webproject works fine.
I understand why I get the ex. but not how to solve it..
UPDATE
Well I fixed the issue by deleting the C:\Users\JRB\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS folder..However now the method always returns false.. It almost seems like it doesn't use the proper connectionstring. Any suggestions?
That particular error message has a lot of possible reasons for it to be generated.
You might want to review this thread on msdn forums for possible solutions.
What it boils down to is that you are using SQL Server Express and the user the web service is executing under has run into a problem. I would guess that problem might be that it is unable to copy the system databases to the local user storage folders. The reason for failure seems to be that you have 2 different applications running under the same user but most likely deployed to two different IIS locations. The first one successfully copies the databases over, the second one fails because the files already exist at that location.
If that's true then you have a couple options. One would be to merge the web service and web application projects that way they are running under the same App instance. Another would be to dump SQL Server Express and move to a more centralized version of SQL server...
A third would be to set up each app to run under different users: ASPNET for the first one and something completely different for the other. However, I don't think this will accomplish what you want.
FYI - SQL Express is purposely not set up to handle this type of configuration. Let me know if I've made a couple incorrect assumptions. We all know how those go. ;)
The WS project actually created a empty membership database by itself and used that, which is why it always returned false.
To fix this I had to copy the webprojects web.config membership tag and add it to the WS web.config and the connection string should be the same of course.
This solution feels a bit dirty but it works..
精彩评论