I have a strange problem for creating my sites programmatically. As a lot of people I know the method CreatePersonalSite of the UserProfile class. My scenario is when a user is clicking on some button it will automatically create his my site by code.
The problem is that it seems to be impossible. Indeed the CreatePersonalSite seems to be dedicated to administration application which has access to MySite content database as dbowner. When I try to do it with the context of the current user who is clicking on the button, I have an access denied from sql server telling me that the service account connecting to the mysite content DB cannot access. Which is normal since the mysite web application is running with another application pool account than the site where the user clicks the button.
So my question is how can I do to create the personal site connected as a normal user on a different web application than the mysite one? I thought about creating a web request to the mysitehost site collection + "/_layouts/mysite.aspx" but this very dirty. Else I can give dbowner access to the my site content db to the application pool account of the web application where the user is clicking the button... but is it safe and can it be done without issues?