Im trying to run an exe file to create a contentdatabase and then create a sitecollection in this database, running this process is working well outside the sharepoint, but when im trying to run it from sharepoint it did nothing and no database creates.

this is my console app (exe file)

 if (args != null)
            string name = args[0];
            string serverName = args[1];
            SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(args[2]));
            SPContentDatabaseCollection dbc = webApplication.ContentDatabases;

            var contentDatabase = new SPContentDatabase();
                contentDatabase = dbc.Add(
                       "WSS_Content_" + name,

and this im running in sharepoint webpart to run the exe file

  ProcessStartInfo pInfo = new ProcessStartInfo(@"C:\CreateContentdb");
                pInfo.CreateNoWindow = false;
                pInfo.UseShellExecute = false;

                var arr = new string[] { name, dbServerName, webApplication.ToString() };
                const string argsSeparator = " ";
                string args = string.Join(argsSeparator, arr);
                pInfo.Arguments = args;

1 Answer 1


I'm afraid a good answer here will always involve not doing such a thing... Launching a new process from a Web (ASP.NET) context is a bad idea. And even worse in the context of SharePoint.

A RunWithElevatedPrivileges call won't change anything here: it just ensures your code runs under the identity of the application pool (see in IIS). For a SharePoint content Web application, this account probably does not have any rights to create a new DB.

On top of that, creating a new process requires other OS-level permissions this account may not have. It would also require an access to the exe, and maybe a loaded profile.

And I don't speak about performances problems and security problems...

In short: you should definetely not do that. The only "clean" way to go is: create a custom SharePoint Timer Job. From your Web part, when the creation of a new DB/new site coll is needed, save the info into a (technical) custom list you created automatically at feature activation.

Every few x [minutes|hours|days] (depending on the volume of DBs/site coll to create and the latency you can accept) the job runs and checks the "queue" (i.e. the custom list that hold the "work-items"). The job runs in OWSTIMER, witch is "SharePoint Timer Service", under "SPFarm": it will have all required permissions/other requirements to fully manage SharePoint by code.

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.