title: Perforce P4 .NET API returns Perforce Password (P4PASSWD) invalid
body: <p>I'm writing a VS C# app using the p4api.net to access a P4 server.  The P4V app accesses the depository fine with a given user/password.  Using p4api.net API, the code executed the Connect() &amp; Login() methods without exception using server/user/password strings passed in from a form:</p>
  
  <pre><code>  rep.Connection.Connect(options);
    rep.Connection.Login(password, options);
  </code></pre>
  
  <p>Below is the actual code:</p>
  
  <pre><code>String conStr = mServerConnection.Text;
  String user = mUserText.Text;
  String password = mPaswordTxt.Text;
  try
  {
     Server server = new Server(new ServerAddress(conStr));
     rep = new Repository(server);
     rep.Connection.UserName = user;
     Options options = new Options();
     Options["Password"] = password;
     rep.Connection.Client = new Client();
     rep.Connection.Connect(options);
     rep.Connection.Login(password, options);
  }
  catch (Exception ex)
  {
     rep = null;
     MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  }
  </code></pre>
  
  <p>However during another call to access the P4 "//depot" root directory, the API call _repository.GetDepotDirs() would return "Perforce Password (P4PASSWD) invalid or unset" exception.  Please see code below:</p>
  
  <pre><code>public bool Expand()
  {
    if (String.IsNullOrEmpty(depotPath))
       return false;
    // if we have the depot path, get a list of the subdirectories from the depot
    if (!String.IsNullOrEmpty(depotPath))
    {
       IList&lt;string&gt; subdirs = _repository.GetDepotDirs(null, String.Format("{0}/*", depotPath));
  </code></pre>
  
  <p>I read somewhere that I need to set the environmental variable P4TICKETS so I did that in a DOS prompt:</p>
  
  <pre><code>p4 set P4TICKETS=C:\Documents and Settings\my_user_name
  </code></pre>
  
  <p>but this didn't resolve the problem.  I'd appreciate your help.  Thanks.</p>