Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Application.ExistsOnSqlServer Method (String, String, String, String)

 

Applies To: SQL Server 2016 Preview

Returns a Boolean that indicates whether the specified package exists on the instance of SQL Server.

Namespace:   Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

public bool ExistsOnSqlServer(
	string packagePath,
	string serverName,
	string serverUserName,
	string serverPassword
)

Parameters

packagePath
Type: System.String

The package you are looking for.

serverName
Type: System.String

The name of the instance of SQL Server to search for the package.

serverUserName
Type: System.String

The user name to authenticate against the instance of SQL Server.

serverPassword
Type: System.String

The password for the specified serverUserName.

Return Value

Type: System.Boolean

true if the package exists on the specified instance of SQL Server. false if the package does not exist.

Legacy Code Example

The following code example creates a SQL Server folder, verifies that it exists, and then removes the folder and rechecks its existence. It also saves a package and verifies that the package was saved using the ExistsOnSqlServer method.

static void Main(string[] args)
        {
            // The variable pkg points to the location
            // of the ExecuteProcess package sample 
            // that is installed with the SSIS samples.
            string p = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx";
            
            Application app = new Application();
            
            // Create a folder on SQL Server in the msdb database.
            app.CreateFolderOnSqlServer("\\", "myNewFolder", "yourserver", null, null);
            
            // Verify that the folder exists by using ExistsOnSqlServer method.
            Boolean folderExists = app.FolderExistsOnSqlServer("myNewFolder", "yourserver", null, null);
            Console.WriteLine("Folder exists? {0}", folderExists);

            // Load a package and save it.
            Package pkg = app.LoadPackage(p, null);
            app.SaveToSqlServerAs(pkg, null, "newPkg", "yourserver", null, null);

            // Verify that the package was saved.
            Boolean packageExists = app.ExistsOnSqlServer("newPkg", "yourserver", null, null);
            Console.WriteLine("Package exists? {0}", packageExists);

            //Remove the folder.
            app.RemoveFolderFromSqlServer("myNewFolder", "yourserver", null, null);

            // Verify that the folder was removed by using the ExistsOnSqlServer method.
            folderExists = app.FolderExistsOnSqlServer("myNewFolder", "yourserver", null, null);
            Console.WriteLine("Folder exists? {0}", folderExists);
        }

Sample Output:

Folder exists? True

Package exists? True

Folder exists? False

Return to top
Show:
© 2015 Microsoft