none
Get ConnectionString of the Project Server by PowerShell RRS feed

  • Question

  • Hi everybody I have a question, it is possible to get the connection string of the project server database, by using C# class that is execute by using a Timer Job?

    Want I mean is, I have a Timer Job that executes a C# class; this class is using the connection string of the project server database that gets some information. i have something that in Project Server 2010 works great, but when I trying to use the same thing in PS 2013 don't works, so I want to use another way to get the connection string.

    I hope that somebody helps me.


    .Net Developer and SharePoint programmer

    Tuesday, October 29, 2013 11:33 PM

All replies

  • What do you have in 2010? You could execute the following PowerShell command from C# Get-SPProjectWebInstance, that will give you the database name / database server.

    http://technet.microsoft.com/en-us/library/ff607531.aspx

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS

    Wednesday, October 30, 2013 9:17 AM
    Moderator
  • Hi Paul, thanks for your answer, but it shows me the next error;

    "You need to have Machine administrator priviliges to run this cmdlet."

    private string RunScript(string scriptText)
            {
                string addWss = "Add-PSSnapin microsoft.sharepoint.powershell";
                StringBuilder stringBuilder = new StringBuilder();
    
                IEnumerable<PSObject> results;
    
                using (var runspace = RunspaceFactory.CreateRunspace())
                {
                    runspace.Open();
                    runspace.SessionStateProxy.SetVariable("prog", this);
    
                    using (var pipeline = runspace.CreatePipeline())
                    {
                        pipeline.Commands.AddScript(addWss);
                        pipeline.Commands.AddScript(scriptText);
    
                        var outDefault = new Command("out-default");
                        outDefault.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
                        pipeline.Commands.Add(outDefault);
    
                        results = pipeline.Invoke();
                    }
                }
    
                foreach (PSObject obj in results)
                {
                    stringBuilder.AppendLine(obj.ToString());
                }
    
                return stringBuilder.ToString();
            }

    I attach the code that I'm using.

    Thanks.


    .Net Developer and SharePoint programmer

    Wednesday, October 30, 2013 9:10 PM