Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

First let me say, that all of we doing in sharepoint is base on the object model, so i can go to Central Administration and get my "Web Analytics Service Application" Database Name and Server Name, and my question is how can i do it with the Sharepoint Object Model?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Function below (edited, will not compile) get the Web Analytics connection for given SPSite

/// /// get Connection string to Web Analytics database /// /// /// public static string GetWAConnectionString(SPSite site) { string sConnectionString = ""; //get web analytics proxy type SPFarm farm = SPFarm.Local;
bool islocalservice = false; try { foreach (SPServiceApplicationProxy pro in site.WebApplication.ServiceApplicationProxyGroup.Proxies) { string s = pro.GetType().ToString();

                if (s == "Microsoft.Office.Server.WebAnalytics.Administration.WebAnalyticsServiceApplicationProxy")
                {
                    SPIisWebServiceApplicationProxy iispro = (SPIisWebServiceApplicationProxy)pro;

                    Uri endpoint = iispro.ServiceEndpointUri;



                    foreach (SPService svc in farm.Services)
                    {


                        if (svc.GetType().ToString() == "Microsoft.Office.Server.WebAnalytics.Administration.WebAnalyticsWebService" && svc.Applications.Count > 0)
                        {
                            foreach (SPServiceApplication app in svc.Applications)
                            {
                                string svid1 = app.Id.ToString();
                                if (!islocalservice)
                                {
                                    //ServiceEndpointUri    {urn:schemas-microsoft-com:sharepoint:service:510a8bf612714e58a3077f0a1f09ac1d#authority=urn:uuid:3ff1d34f9e994f939ebee8df59ff77b5&authority=https://irene2010rtm:32844/Topology/topology.svc}
                                    islocalservice = endpoint.AbsolutePath.ToLower().EndsWith(svid1.ToLower().Replace("-", ""));
                                    if (islocalservice)
                                    {
                                        Type objectType = app.GetType();
                                        PropertyInfo WS = objectType.GetProperty("WarehouseSubscriptions");
                                        if (WS != null)
                                        {
                                            object o = WS.GetValue(app, null);
                                            if (o != null)
                                            {
                                                string sDatabases = o.ToString();
                                                XmlDocument doc = new XmlDocument();
                                                doc.LoadXml(sDatabases);
                                                if (doc.ChildNodes.Count > 0 && doc.ChildNodes[0].ChildNodes.Count > 0)
                                                {
                                                   // WarehouseSubscriptions:   "<ReportingDatabases><ReportingDatabase>Irene2010RTM;WebAnalyticsServiceApplication_ReportingDB_0682c2f1-c019-4e1e-939f-2c0c1a6ea381</ReportingDatabase></ReportingDatabases>"
                                                    string sDb = doc.ChildNodes[0].ChildNodes[0].InnerText;

                                                    string[] props = sDb.Split(new char[] { ';' });
                                                    if (props.Length >= 2)
                                                    {
                                                        //get Web Analytics databases
                                                        SPDatabaseService dbService = SPFarm.Local.Services.GetValue<SPDatabaseService>();
                                                        // Enumerate the service instances
                                                        foreach (SPDatabaseServiceInstance instance in dbService.Instances)
                                                        {
                                                            if (instance.Status == SPObjectStatus.Online)
                                                                // enumerate the databases within this service instance
                                                                foreach (SPDatabase database in instance.Databases)
                                                                {
                                                                    object oDB = database.GetType();
                                                                    // If the objects type is "Microsoft.Office.Server.WebAnalytics.Administration.WebAnalyticsWarehouseDatabase", you've found the Web Analytics DB.
                                                                    if (oDB.ToString().CompareTo(@"Microsoft.Office.Server.WebAnalytics.Administration.WebAnalyticsWarehouseDatabase") == 0)
                                                                    {
                                                                        if (database.Server.Name.ToLower() == props[0].Trim().ToLower() && database.Name.ToLower() == props[1].Trim().ToLower())
                                                                        {
                                                                            //after much trouble we found a database
                                                                            sConnectionString = database.DatabaseConnectionString;
                                                                            LoggingUtil.WriteTrace(TraceLevel.Info, "Analytics ConnectionString found:" + sConnectionString, Switch);


                                                                        }
                                                                    }
                                                                }
                                                        }
                                                    }



                                                }

                                            }
                                        }


                                    }

                                }


                            }
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            LoggingUtil.WriteTrace(System.Diagnostics.TraceLevel.Warning, "Cannot get WA connection:" + e.ToString(), Switch);
        }

        return sConnectionString;
    }
share|improve this answer
1  
fantastic man if it works you just saved the day, thanks. –  Jalali Shakib Jul 28 '11 at 3:51
1  
that's worked just fine. how you came upon with this? –  Jalali Shakib Jul 28 '11 at 4:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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