FolderExistsOnSqlServer 方法

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

命名空间:  Microsoft.SqlServer.Dts.Runtime
程序集:  Microsoft.SqlServer.ManagedDTS(在 Microsoft.SqlServer.ManagedDTS.dll 中)

语法

声明
Public Function FolderExistsOnSqlServer ( _
    strFolderName As String, _
    strServerName As String, _
    strServerUserName As String, _
    strServerPassword As String _
) As Boolean
用法
Dim instance As Application
Dim strFolderName As String
Dim strServerName As String
Dim strServerUserName As String
Dim strServerPassword As String
Dim returnValue As Boolean

returnValue = instance.FolderExistsOnSqlServer(strFolderName, _
    strServerName, strServerUserName, _
    strServerPassword)
public bool FolderExistsOnSqlServer(
    string strFolderName,
    string strServerName,
    string strServerUserName,
    string strServerPassword
)
public:
bool FolderExistsOnSqlServer(
    String^ strFolderName, 
    String^ strServerName, 
    String^ strServerUserName, 
    String^ strServerPassword
)
member FolderExistsOnSqlServer : 
        strFolderName:string * 
        strServerName:string * 
        strServerUserName:string * 
        strServerPassword:string -> bool 
public function FolderExistsOnSqlServer(
    strFolderName : String, 
    strServerName : String, 
    strServerUserName : String, 
    strServerPassword : String
) : boolean

参数

  • strServerName
    类型:System. . :: . .String
    The name of the instance of SQL Server to search for the package.
  • strServerUserName
    类型:System. . :: . .String
    The SQL Server login name if you use SQL Server Authentication to log into the server; otherwise, nullNothingnullptrunitnull 引用(在 Visual Basic 中为 Nothing) if you use Windows Authentication.
  • strServerPassword
    类型:System. . :: . .String
    The SQL Server login password if you use SQL Server Authentication to log into the server; otherwise, nullNothingnullptrunitnull 引用(在 Visual Basic 中为 Nothing) if you use Windows Authentication.

返回值

类型:System. . :: . .Boolean
true if the folder exists on the specified instance of SQL Server; false if the folder does not exist.

示例

The following code example creates a folder on SQL Server, renames it, and then removes it. It also verifies the existence of the folder by using FolderExistsOnSqlServer.

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 pkg = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx";

            Application app = new Application();
            app.CreateFolderOnSqlServer("\\", "myNewFolder", "yourserver", null, null);
            
            // Verify that the folder was created.
            Boolean ssFolder = app.FolderExistsOnSqlServer("\\myNewFolder", "yourserver", null, null);
            Console.WriteLine("myNewFolderExists? " + ssFolder);

            // Rename the myNewFolder to myRenamedFolder. 
            app.RenameFolderOnSqlServer("\\", "myNewFolder", "myRenamedFolder", "yourserver", null, null);

            // Verify that the old folder does not exist.
            ssFolder = app.FolderExistsOnSqlServer("\\myNewFolder", "yourserver", null, null);
            Console.WriteLine("myNewFolderExists has been renamed but still exists? " + ssFolder);

            // Verify that a folder with the new name does exist.
            ssFolder = app.FolderExistsOnSqlServer("\\myRenamedFolder", "yourserver", null, null);
            Console.WriteLine("myRenamedFolder now exists? " + ssFolder);

            // Delete the folder.
            app.RemoveFolderFromSqlServer("\\myRenamedFolder", "yourserver", null, null);

            // Verify that the folder was removed.
            ssFolder = app.FolderExistsOnSqlServer("\\myRenamedFolder", "yourserver", null, null);
            Console.WriteLine("myRenamedFolder still exists? " + ssFolder);
        }
Sub Main(ByVal args() As String)
            ' The variable pkg points to the location
            ' of the ExecuteProcess package sample 
            ' that is installed with the SSIS samples.
            Dim pkg As String =  "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx" 
 
            Dim app As Application =  New Application() 
            app.CreateFolderOnSqlServer("\\", "myNewFolder", "yourserver", Nothing, Nothing)
 
            ' Verify that the folder was created.
            Dim ssFolder As Boolean =  app.FolderExistsOnSqlServer("\\myNewFolder","yourserver",Nothing,Nothing) 
            Console.WriteLine("myNewFolderExists? " + ssFolder)
 
            ' Rename the myNewFolder to myRenamedFolder. 
            app.RenameFolderOnSqlServer("\\", "myNewFolder", "myRenamedFolder", "yourserver", Nothing, Nothing)
 
            ' Verify that the old folder does not exist.
            ssFolder = app.FolderExistsOnSqlServer("\\myNewFolder", "yourserver", Nothing, Nothing)
            Console.WriteLine("myNewFolderExists has been renamed but still exists? " + ssFolder)
 
            ' Verify that a folder with the new name does exist.
            ssFolder = app.FolderExistsOnSqlServer("\\myRenamedFolder", "yourserver", Nothing, Nothing)
            Console.WriteLine("myRenamedFolder now exists? " + ssFolder)
 
            ' Delete the folder.
            app.RemoveFolderFromSqlServer("\\myRenamedFolder", "yourserver", Nothing, Nothing)
 
            ' Verify that the folder was removed.
            ssFolder = app.FolderExistsOnSqlServer("\\myRenamedFolder", "yourserver", Nothing, Nothing)
            Console.WriteLine("myRenamedFolder still exists? " + ssFolder)
End Sub

Sample Output:

myNewFolderExists? True

myNewFolderExists has been renamed but still exists? False

myRenamedFolder now exists? True

myRenamedFolder still exists? False