3

I am searching for a solution of my problem. I banged my head for the last few hours and tried several things and solutions found on google or stack-exchange.

The database should be created via Event Receiver. I know that elevated prev impersonate as the app pool account which has not enough rights to create a database. But even as a farm admin on my development machine (there is only one account for all services, app pools and so on) I run into an access denied (with the super admin itself :-D )

I don´t know how to go on. Is it possible to SQL authentication and use a SQL user in some way? I tried this way on my development machine with the sa user and the right password BUT access denied.

Due to the fact that this should be a self service solution timer jobs are no solution for me :-( WebService and farm application page are not the best way from my point of view.

  • where it is getting access denied...on SQL server or on the sharepoint server? can you share the error details and code as well...if possible share screen shot – Waqas Sarwar MVP Oct 16 '15 at 21:24
  • getting the error while debugging my solution in VS2013. The error says that the server is not available (but it is, checked with UDL file) or the user has not enough rights (if I use the AD account) or is says directly access denied while using the sa account from SQL. But when I check the connection to the SQL server with the UDL file, there is no access denied with the sa account. – Felix Zeidler Oct 17 '15 at 10:20
  • It´s an exception, no SqlExcetion. But I assume that the access denied comes from the SQL. – Felix Zeidler Oct 17 '15 at 10:29
4

It happens from time to time, in the server OM, there's a check against the context (Web or not) so some operations are forbidden even if the identity running the code has the correct permissions.

You don' want to consider a timer job, but in your case I would think again: with a timer job you'd have no problem at all.
That job could be a work item job, and run every x minutes (even with x=1) to check the queue of work item. If nothing in the queue, it does nothing, thus consummes no resources. If there's a work item, it creates the DB (which is by the way a very long operation, so the x minutes delay the job adds may not be a problem).

I would really consider that approach, since it frees you from permissions/Web contexts problem, avoid potential security holes, and prevent you from running a very long operation from the ER/Web context.

  • Well, maybe I need to overthink... But there is no way to use a SQL user to add/create a new database through an ER? – Felix Zeidler Oct 17 '15 at 10:27
  • Yes, probably... but do you know how to create that new content DB? What settings. What permissions? And most importantly, what schema? Anyway, this will be completely not supported. And definitely not falling into the philisophy of ER and Web contexts... – Evariste Oct 17 '15 at 10:32
  • If these points are coming up I prefer the workitem TJ ^^ – Felix Zeidler Oct 17 '15 at 11:01
  • Wise decision :) In your position, I would surely go with the work item job! – Evariste Oct 17 '15 at 11:09
  • There is only one point left. In the productive environment the solution is a self service application and I need to check whether there is already a workItem for the creating a cdb for the specific web application. But I think this is possible, isn´t it? – Felix Zeidler Oct 17 '15 at 11:32
0

This thing is driving me crazy so I need to ask a few questions.

This is how I "create" the job:

CreateDBWorkItemTimerJob job = new CreateDBWorkItemTimerJob(JobName, webApp);

SPMinuteSchedule schedule = new SPMinuteSchedule();

schedule.BeginSecond = 0;
schedule.Interval = 1;
schedule.EndSecond = 59;

job.Schedule = schedule;
job.Update();

based on that:

public CreateDBWorkItemTimerJob(string name, SPWebApplication webApplication)
            : base(name, webApplication, null, SPJobLockType.None)
        {
            this.Title = "Create new ContentDB for WebApplication";
        }

No error but still no job in the job list. What´s wrong? I also tried to use it with a SPOneTimeSchedule - no luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.