Showing posts with label objects. Show all posts
Showing posts with label objects. Show all posts

Saturday, February 25, 2012

Process cannot connect to distributor error !!!

Hey guys. I am creating an app that uses the RMO Merge Replication objects.
So far it can subscribe and unsubscribe just fine but when it comes to the syncing process it gets a little weird, here's why.

- If I run the SQL GUI Sync tool, it sinks fine. So that setup is working.

- When I run the C# App it blows up witht the error: "Process cannot connect to Distributor"

- Here's the weird part: When I set a breakpoint on my custom method SyncData (this method sets up the connection info and properties and then calls Syncronize( ) ) and step through the code when it gets to Syncronize( ) it runs perfectly fine, no execeptions.

I thought that maybe the Syncronize( ) method was being called too fast before the connection properties got to fully setup and connect, so I added a Thread.Sleep( ) method for 10 secs after each connection call and just before calling Syncronize( ). It still didn't work. My class is a static class by design, however, I changed it into an ordinary class and then placed the connection info in the constructor hoping it would do it's connection when the object gets initialized, that didn't work either.

If someone could please help me out with this I would greatly appreciate it.

Here's my code:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Replication;
using Microsoft.SqlServer.Replication.BusinessLogicSupport;
using Microsoft.SqlServer.Management.Common;
using System.Windows.Forms;
using System.Threading;

namespace Emds.Briefcase.BriefcaseSubscriber.BLL
{
public class SyncDataClass
{
#region Members

private static string m_statusMessage = string.Empty;
private static byte m_percentComplete;
public delegate void StatusTextChangeHandler(int percent, string status);
public static event StatusTextChangeHandler OnStatusChange;

#endregion Members

#region Methods

public static string SyncData()
{

//Delay();

// Define the server, publication, and database names.
string publicationName = "Chart";
string publisherName = @."JSMITH\SQL2005";
string subscriberName = @."JDOE\SQL2005";
string subscriptionDbName = "DataSubscriber";
string publicationDbName = "DataPublisher";
string message = string.Empty;

// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);

MergePullSubscription subscription;

try
{
// Connect to the Subscriber.
conn.Connect();
// Delay();

// Define the pull subscription.
subscription = new MergePullSubscription();
subscription.ConnectionContext = conn;

//Delay();

subscription.DistributorSecurity.WindowsAuthentication = false;
subscription.DistributorSecurity.SqlStandardLogin = "sa";
subscription.DistributorSecurity.SqlStandardPassword = "russell";

// Delay();
subscription.PublisherName = publisherName;
subscription.PublicationDBName = publicationDbName;
subscription.PublicationName = publicationName;
subscription.PublisherSecurity.SecurityMode = ReplicationSecurityMode.SqlStandard;
subscription.PublisherSecurity.SqlStandardLogin = "sa";
subscription.PublisherSecurity.SqlStandardPassword = "russell";

// Delay();
subscription.DatabaseName = subscriptionDbName;
subscription.SubscriberSecurity.WindowsAuthentication = false;
subscription.SubscriberSecurity.SqlStandardLogin = "sa";
subscription.SubscriberSecurity.SqlStandardPassword = "russell";

// Delay();

// If the pull subscription exists, then start the synchronization.
if (subscription.LoadProperties())
{

// Check that we have enough metadata to start the agent.
if (subscription.PublisherSecurity != null || subscription.DistributorSecurity != null)
{
// Synchronously start the Merge Agent for the subscription.
subscription.SynchronizationAgent.Status += new AgentCore.StatusEventHandler(SynchronizationAgent_Status);
// Delay();

subscription.SynchronizationAgent.Synchronize();
message = "Data Syncronization is a success!";
}
else
{
throw new ApplicationException("There is insufficent metadata to " +
"synchronize the subscription. Recreate the subscription with " +
"the agent job or supply the required agent properties at run time.");
}
}
else
{
// Do something here if the pull subscription does not exist.
throw new ApplicationException(String.Format(
"A subscription to '{0}' does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement appropriate error handling here.
throw new ApplicationException("The subscription could not be " +
"synchronized. Verify that the subscription has " +
"been defined correctly.", ex);
}
finally
{
conn.Disconnect();
}
return message;
}

static void SynchronizationAgent_Status(object sender, StatusEventArgs e)
{
m_percentComplete = e.PercentCompleted;
m_statusMessage = e.Message;

//Fire custom event
if (OnStatusChange != null)
{
OnStatusChange(m_percentComplete, m_statusMessage);
}
}

#endregion Methods
}
}Moved to SQL Server Replication forum.|||

You may want to try setting the distributor security on the Agent object directly before calling subscription.SynchronizationAgent.Synchronize() like so:

subscription.SynchronizationAgent.DistributorSecurityMode = SecurityMode.Standard

subscription.SynchronizationAgent.DistributorLogin = "sa"

subscription.SynchronizationAgent.DistributorPassword = "russell"

Hope that helps,

-Raymond

|||Raymond,

Thanks for your response. If you look at my code listing I think you will see that I am already doing that, unless I missunderstood what you were suggesting.

Thanks again,

Chris|||

There is actually a subtle difference: I believe your code is setting the security info on the subscription object, whereas my code is setting it on the SynchronizationAgent object.

-Raymond

|||Ok, I will give it a shot. Thank you again!!|||That was it!!! Thank you very, very much!!!!!

Take care!!!

process analysis server objects from web via ASP.NET + C#

Hi!

We are running several Analysis Services Cubes on a Database Server (SQL 2005) machine.

Another machine is our web server (IIS, ASPX) which displays cube

content and allows drill down to several levels. Everything works fine

and we are looking forward to optimizing the whole data management

process. At the moment we try to develop DTS packeges (SQL 2005).

Is it possible to initiate a cube processing (without DTS in the background) from eg an administration section in the web page?

TIA and kind regards from Vienna

JohnnyR

You can use AMO (Microsoft.AnalysisServices.dll from "%ProgramFiles%\Microsoft SQL Server\90\SDK\Assemblies"). If IIS impersonates the current user, then AMO code from the administration aspx page would also connect to AS2005 as that user. The user needs read permission for the Database and read+process permissions for the Cube.

Sample code:

using Microsoft.AnalysisServices;

...

Server server = new Server();
server.Connect("localhost");
try
{
server.Databases["the ID of the database"].Cubes["the ID of the cube"].Process();
}
finally
{
server.Disconnect();
}

You can also get processing notifications with AMO, to display progress on the administration page; more details here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=75148&SiteID=1

Adrian Dumitrascu

|||

Hi,

I have created an analysis services project using SQL Server 2005, in which I have included a cube, dimension, data source and data view. Now using the Analysis services Browser tab of cube I can see the Pivot table exactly the way I want where I can drag & drop table fields as per my requirements. But I am struggling to display the same cube over the Web. Can any please tell me that how I can publish the contents of Cube i.e. Pivot table on a web application so that end user can use this. I want the same functionality, which I can see in the Browser tab of Cube in AS2005 i.e. user should have freedom to drag & drop the fields exactly like in Excel Pivot table.

Any help would be highly appreciated.

Thanks in advance.

|||

The control used in the browser is the Office Web Components 11.0 PivotTable control.

You can use this control in your asp.net app by referencing this control in the COM tab.

As to how to use it.. documentation is sparse, so I'd just do a search on the web.

Alternatively, you could host thepivot table in an Excel spread sheet and publish that as a web page... use Excel 2007 for the best experience... again, do a search on Excel services.

Otherwise, there are true .NEt controls, such as those produced by RadarSoft

process analysis server objects from web via ASP.NET + C#

Hi!

We are running several Analysis Services Cubes on a Database Server (SQL 2005) machine.

Another machine is our web server (IIS, ASPX) which displays cube

content and allows drill down to several levels. Everything works fine

and we are looking forward to optimizing the whole data management

process. At the moment we try to develop DTS packeges (SQL 2005).

Is it possible to initiate a cube processing (without DTS in the background) from eg an administration section in the web page?

TIA and kind regards from Vienna

JohnnyR

You can use AMO (Microsoft.AnalysisServices.dll from "%ProgramFiles%\Microsoft SQL Server\90\SDK\Assemblies"). If IIS impersonates the current user, then AMO code from the administration aspx page would also connect to AS2005 as that user. The user needs read permission for the Database and read+process permissions for the Cube.

Sample code:

using Microsoft.AnalysisServices;

...

Server server = new Server();
server.Connect("localhost");
try
{
server.Databases["the ID of the database"].Cubes["the ID of the cube"].Process();
}
finally
{
server.Disconnect();
}

You can also get processing notifications with AMO, to display progress on the administration page; more details here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=75148&SiteID=1

Adrian Dumitrascu

|||

Hi,

I have created an analysis services project using SQL Server 2005, in which I have included a cube, dimension, data source and data view. Now using the Analysis services Browser tab of cube I can see the Pivot table exactly the way I want where I can drag & drop table fields as per my requirements. But I am struggling to display the same cube over the Web. Can any please tell me that how I can publish the contents of Cube i.e. Pivot table on a web application so that end user can use this. I want the same functionality, which I can see in the Browser tab of Cube in AS2005 i.e. user should have freedom to drag & drop the fields exactly like in Excel Pivot table.

Any help would be highly appreciated.

Thanks in advance.

|||

The control used in the browser is the Office Web Components 11.0 PivotTable control.

You can use this control in your asp.net app by referencing this control in the COM tab.

As to how to use it.. documentation is sparse, so I'd just do a search on the web.

Alternatively, you could host thepivot table in an Excel spread sheet and publish that as a web page... use Excel 2007 for the best experience... again, do a search on Excel services.

Otherwise, there are true .NEt controls, such as those produced by RadarSoft