Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

ReplicationObject.LoadProperties Method

Definition

Namespace:
Microsoft.SqlServer.Replication
Assembly:
Microsoft.SqlServer.Rmo.dll

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Loads the properties of an existing object from the server.

public:
 bool LoadProperties();
public bool LoadProperties();
member this.LoadProperties : unit -> bool
Public Function LoadProperties () As Boolean

Returns

A Boolean value. If true, the object exists on the instance of Microsoft SQL Server. If false, the object does not exist on the instance of SQL Server.

Examples

// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";

MergePublication publication;

// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

try
{
 // Connect to the Publisher.
 conn.Connect();

 // Set the required properties for the publication.
 publication = new MergePublication();
 publication.ConnectionContext = conn;
 publication.Name = publicationName;
 publication.DatabaseName = publicationDbName;


 // If we can't get the properties for this merge publication, then throw an application exception.
 if (publication.LoadProperties())
 {
 // If DDL replication is currently enabled, disable it.
 if (publication.ReplicateDdl == DdlReplicationOptions.All)
 {
 publication.ReplicateDdl = DdlReplicationOptions.None;
 }
 else
 {
 publication.ReplicateDdl = DdlReplicationOptions.All;
 }
 }
 else
 {
 throw new ApplicationException(String.Format(
 "Settings could not be retrieved for the publication. " +
 "Ensure that the publication {0} exists on {1}.",
 publicationName, publisherName));
 }
}
catch (Exception ex)
{
 // Do error handling here.
 throw new ApplicationException(
 "The publication property could not be changed.", ex);
}
finally
{
 conn.Disconnect();
}
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"

Dim publication As MergePublication

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Try
 ' Connect to the Publisher.
 conn.Connect()

 ' Set the required properties for the publication.
 publication = New MergePublication()
 publication.ConnectionContext = conn
 publication.Name = publicationName
 publication.DatabaseName = publicationDbName

 ' If we can't get the properties for this merge publication, then throw an application exception.
 If publication.LoadProperties() Then
 ' If DDL replication is currently enabled, disable it.
 If publication.ReplicateDdl = DdlReplicationOptions.All Then
 publication.ReplicateDdl = DdlReplicationOptions.None
 Else
 publication.ReplicateDdl = DdlReplicationOptions.All
 End If
 Else
 Throw New ApplicationException(String.Format( _
 "Settings could not be retrieved for the publication. " + _
 "Ensure that the publication {0} exists on {1}.", _
 publicationName, publisherName))
 End If
Catch ex As Exception
 ' Do error handling here.
 Throw New ApplicationException( _
 "The publication property could not be changed.", ex)
Finally
 conn.Disconnect()
End Try

Remarks

If properties have already been loaded, they will not be reloaded. If they are not current, call the Refresh method on the object to refresh the properties.

If sufficient information about this object is missing, an exception is raised. If the object does not exist on the server, the method returns false. Otherwise, properties are loaded and the method returns true.

Applies to