How do I test the availability of a remote directory through SSIS?

I'm currently trying to test and see if a remote directory exists and able to be opened using a C# Script task in SSIS 2008.  The problem is that when I run the package during testing, the task succeeds even when the remote directory isn't available.  I'm using the code below:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;

namespace ST_e38fcd12a33d474e80abe495322e7d80.csproj
{
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        public void Main()
        {

            string path = @"\\MyComp\C$\Temp\\";

            try
            {
                Directory.SetCurrentDirectory(path);
                Dts.TaskResult = (int)ScriptResults.Success;
                System.Console.WriteLine(Dts.TaskResult);
            }
            catch (Exception e)
            {
                Dts.TaskResult = (int)ScriptResults.Failure;
                System.Console.WriteLine(Dts.TaskResult);
                throw e;
            }
        }
    }
}

Even when the remote directory isn't available on the network, the task still hits the succeed email task.  I imagine it's probably something simple I'm missing, can someone help point it out?

Thanks,
Glen
jisoo411Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Christopher GordonSenior Developer AnalystCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jisoo411Author Commented:
I'll give the Directory.Exists() method a try, although my concern at the moment is that I've physically disabled network file sharing on that remote directory folder and the script task still evaluated to success.  Hopefully Directory.Exists() resolves this.
jisoo411Author Commented:
So I tried the directory.exists() method but I'm running into the same problem, even when the directory I'm looking for is disabled the script task still evaluates to success.  I've redone the code like this:

        public void Main()
        {
            // TODO: Add your code here
            string path = @"\\MyComp\C$\Temp\\";

            if (Directory.Exists(path))
            {
                Dts.TaskResult = (int)ScriptResults.Success;
            }
            else
            {
                Dts.TaskResult = (int)ScriptResults.Failure;
            }
        }

Theoretically it should fail the task and hence send me the failure email I'm expecting (I have two email tasks attached to this script task, one with a success constraint and one with a failure constraint).  Am I missing something?  
Christopher GordonSenior Developer AnalystCommented:
Your code looks right to me.  

So
1. "\\MyComp" is a PC on your network that is different from the machine you're running the SSIS package on.  

2. You have an ADMIN account configured on the remote machine "MyComp"

The only thing I can think of (and this is a shot in the dark) is that your use of the ADMIN share (\\MyComp\C$)  to access Temp on the remote machine is somehow bypasses the network file sharing being disabled.  

If "MyComp" is running on the same machine as SSIS, disabling network sharing is probably moot (since it's not reaching out to your network) -- Note: I didn't verify/ just assumed this point.

If "MyComp" is remote try making a share for the Temp folder on the remote machine "\\MyComp" called "Temp" and change your script to this:

        public void Main()
        {
            try
            {
            // TODO: Add your code here
            string path = @"\\MyComp\Temp\";

            if (Directory.Exists(path))
            {
                Dts.TaskResult = (int)ScriptResults.Success;
            }
            else
            {
                Dts.TaskResult = (int)ScriptResults.Failure;
            }
            }
            catch
           {
                Dts.TaskResult = (int)ScriptResults.Failure;
            }
        }

Thus bypassing use of Admin share.

Sorry for the delay in getting back to your thread.
jisoo411Author Commented:
Your thoughts helped me figure out what was going on.  The shared folder is on my local workstation while the SSIS package is stored and run on a separate physical server across the network.  I've been invoking the SSIS package by logging into that server across the network via remote desktop connection but since I was using my Windows domain login (which I also use on my local workstation), I still had full admin rights to access whatever folders I wanted even with file sharing disabled.  I had someone else log in and run the SSIS package and it provided the expected results (failure detected due to no available file share).  

Thanks for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.