Background: An application that opens a file, searches the file for the old password, replace the old password, and then saves an closes the file. The file is used by another process.

Servers
I have two environments one for dev and prd.

The Issue
* On prod the files are opened and saved with the current date and time, but the previous password is not replaced.

* On dev the files are opened, replaced, and saved correctly with the new password.


Things I Have Tried
* Check file permissions between the two environment and found that it was not an issue
* Implemented an error system to see if there is an error message. none are being returned
* Implemented a check to see if the file are out of sync the log and password in the file

What I think it is
There are three major differences between the two environments
* MSXML 6 Service Pack 2 (KB973686) 6.20.2003.0
* Security Update for Microsoft .NET Framework 3.5 SP1 (KB2416473) 1
* Update for Microsoft .NET Framework 3.5 SP1 (KB963707) 1


If you can help me, that would be sweet. I provided the code that does the replace below.
If i need to make something more clear please let me know.

string passwordLog = _appDrive + @"Apps\FTP\Password\Password_Log.txt";
			   StreamReader sr = new StreamReader(file);
            StreamReader pl = new StreamReader(passwordLog);

			   //read the entire file at once
			   string contents = sr.ReadToEnd();
            string oldContents = contents;
            string contents2 = pl.ReadToEnd();			   
			   
            //close up file
			   sr.Close();		
            pl.Close();   
			   
            //use regular expressions to search and replace our text
            //added to search if previous password is found in content
            bool search1 = Regex.IsMatch(contents,searchFor);
            //searches for previous password in log
            bool search2 = Regex.IsMatch(contents2, searchFor);
            
            string newContents = null;

            if (search1)
            {
               WriteProcessLog("Password was found in file stream" + file);
               WriteProcessLog("serachFor:" + searchFor + "| replaceWith:" + replaceWith);
			      newContents = Regex.Replace(contents, searchFor, replaceWith, RegexOptions.None);			   
            }
            else
            {
               //the will update files that are out of sync              
               if (search2)
               {
                  string[] words = contents.Split(' ');
                  bool checkNext = false;
                  int i=0;
                  WriteProcessLog("Password was found in file password log");
                  foreach (string w in words)
                  {
                     if (checkNext)
                     {
                        //checkNext = false;
                        //sets the password in file to searchFor if out of sync
                        searchFor = w.Trim();
                        WriteProcessLog("Password in file:" + searchFor);
                        break;
                     }

                     if (w == "-p")
                     { 
                        i++;
                     }

                     if(w == "-p" && i == 2 )
                     {
                        checkNext = true; 
                     }
                  }
               }
                 //searches the file for  the new searchFor
                 search1 = Regex.IsMatch(contents2, searchFor);//search log for password in log

                 if (search1)
                 {
                    //if new searchFor is found then updates the file
                    

                    var regex = new Regex(searchFor, RegexOptions.Compiled);
                    Match match = regex.Match(searchFor); 
                    if (!match.Success)
                    {
                       foreach (var currentMatch in regex.Matches(contents))
                       {
                          newContents = Regex.Replace(contents, searchFor, replaceWith, RegexOptions.None);
                       }
                    }
                    else
                    {
                       newContents = oldContents;
                    }

                    WriteProcessLog("serachFor:" + searchFor + " | replaceWith:" + replaceWith);
                 }
                 else
                 {
                    WriteProcessLog("Not found in password log | serachFor:" + searchFor + " | in file" + file);
                    ChangeStatus("Fail", "Files Are Out of Sync. " + file);
                    throw new Exception("Files Are Out of Sync. " + file);
                 }
            }

            //get a StreamWriter for writing the new text to the file 
          using (StreamWriter sw = File.CreateText(file))
          {
             //write the contents
             try
             {
                sw.Write(newContents);
                WriteProcessLog("Writing new contents");
                sw.Close();
             }
             catch (Exception writeEx)
             {
                ChangeStatus("Fail", writeEx.Message);
                throw new Exception(writeEx.Message);
             }

          }

1) What are your includes?
2) Have you tried to write to a different directory on the production machine?
3) Have you tried just writing a comment into the production file?

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Net.Mail;
using System.Configuration;
using ***.Logging; // company files i didnt feel right showing the name of the company
using ***.Password;

I have tried different directories. Started new files. Tried different named of files and types. The same outcome. I tried to throw an error when regex.success was false and it always returns true and the comment always says it is successful, when it did not change anything. I also store the old file and compare the new to the old and again in dev it works fine, but prd it didn’t.

If you've tried different directories, I can only imagine it is a permissions problem.
Hmmm...

Are the servers using the same OS?
Could it be a security update preventing this?

- I once had a security update foil my new technology 1 day after writing the code.

Both OS'es are Windows Server 2003 and I have had the head of security check permissions and they are both the same for any user or program that may edit the file.

If it is a security update how would i figure that out. Is there a site that tells me what each update fixes?

I wish I could tell the server admins to include all updates but if the updates cause an error on our prd server there are some high paying fines that follow with the rebuild of a server.

I have not found what I consider to be the BEST solution for finding updates, but I would go into Control Panel->Add Remove Programs and click the "Show updates" checkbox.

You can then stare-and-compare to see if there are any different security updates.
Just looking for differences might be easier than reading the docs on what the updates do. :|

I know the differences they are listed below, but i have to provide a reason why certain ones has to be installed and not say well all of these need to be updated. Needle in a haystack ordeal here.

I just didnt know if there was a way to see what was updated in these to i can give a definated yes and no to some of these without worry of breaking the prod server.


Hotfix for Windows Server 2003 (KB2570791) 1
Hotfix for Windows Server 2003 (KB961118) 1
Hotfix for Windows Server 2003 (KB970653-v3) 3
Hotfix for Windows Server 2003 (KB976098-v2) 2
Hotfix for Windows Server 2003 (KB979306) 1
Hotfix for Windows Server 2003 (KB981793) 1
MSXML 6 Service Pack 2 (KB973686) 6.20.2003.0
Security Update for Microsoft .NET Framework 3.5 SP1 (KB2416473) 1
Security Update for Microsoft Windows (KB2564958)
Security Update for Windows Server 2003 (KB2121546) 1
Security Update for Windows Server 2003 (KB2160329) 1
Security Update for Windows Server 2003 (KB2259922) 1
Security Update for Windows Server 2003 (KB2279986) 1
Security Update for Windows Server 2003 (KB2296011) 1
Security Update for Windows Server 2003 (KB2360937) 1
Security Update for Windows Server 2003 (KB2378111) 1
Security Update for Windows Server 2003 (KB2387149) 1
Security Update for Windows Server 2003 (KB2393802) 1
Security Update for Windows Server 2003 (KB2416451) 1
Security Update for Windows Server 2003 (KB2423089) 1
Security Update for Windows Server 2003 (KB2436673) 1
Security Update for Windows Server 2003 (KB2440591) 1
Security Update for Windows Server 2003 (KB2443105) 1
Security Update for Windows Server 2003 (KB2476687) 1
Security Update for Windows Server 2003 (KB2478960) 1
Security Update for Windows Server 2003 (KB2478971) 1
Security Update for Windows Server 2003 (KB2479628) 1
Security Update for Windows Server 2003 (KB2503658) 1
Security Update for Windows Server 2003 (KB2503665) 1
Security Update for Windows Server 2003 (KB2506223) 1
Security Update for Windows Server 2003 (KB2507938) 1
Security Update for Windows Server 2003 (KB2536276-v2) 2
Security Update for Windows Server 2003 (KB2544521)
Security Update for Windows Server 2003 (KB2544893) 1
Security Update for Windows Server 2003 (KB2544893-v2) 2
Security Update for Windows Server 2003 (KB2555917) 1
Security Update for Windows Server 2003 (KB2562937) 1
Security Update for Windows Server 2003 (KB2566454) 1
Security Update for Windows Server 2003 (KB2567053) 1
Security Update for Windows Server 2003 (KB2567680) 1
Security Update for Windows Server 2003 (KB2570222) 1
Security Update for Windows Server 2003 (KB2572069) 1
Security Update for Windows Server 2003 (KB2586448) 1
Security Update for Windows Server 2003 (KB2592799) 1
Security Update for Windows Server 2003 (KB942830) 1
Security Update for Windows Server 2003 (KB942831) 1
Security Update for Windows Server 2003 (KB960859) 1
Security Update for Windows Server 2003 (KB968537) 1
Security Update for Windows Server 2003 (KB969059) 1
Security Update for Windows Server 2003 (KB970238) 1
Security Update for Windows Server 2003 (KB970483) 1
Security Update for Windows Server 2003 (KB971032) 1
Security Update for Windows Server 2003 (KB971468) 1
Security Update for Windows Server 2003 (KB971486) 1
Security Update for Windows Server 2003 (KB971657) 1
Security Update for Windows Server 2003 (KB973904) 1
Security Update for Windows Server 2003 (KB974392) 1
Security Update for Windows Server 2003 (KB974571) 1
Security Update for Windows Server 2003 (KB975254) 1
Security Update for Windows Server 2003 (KB975467) 1
Security Update for Windows Server 2003 (KB960859) 1
Security Update for Windows Server 2003 (KB968537) 1
Security Update for Windows Server 2003 (KB969059) 1
Security Update for Windows Server 2003 (KB970238) 1
Security Update for Windows Server 2003 (KB970483) 1
Security Update for Windows Server 2003 (KB971032) 1
Security Update for Windows Server 2003 (KB971468) 1
Security Update for Windows Server 2003 (KB971486) 1
Security Update for Windows Server 2003 (KB971657) 1
Security Update for Windows Server 2003 (KB973904) 1
Security Update for Windows Server 2003 (KB974392) 1
Security Update for Windows Server 2003 (KB974571) 1
Security Update for Windows Server 2003 (KB975254) 1
Security Update for Windows Server 2003 (KB975467) 1
Security Update for Windows Server 2003 (KB978037) 1
Security Update for Windows Server 2003 (KB978338) 1
Security Update for Windows Server 2003 (KB978706) 1
Security Update for Windows Server 2003 (KB979559) 1
Security Update for Windows Server 2003 (KB979683) 1
Security Update for Windows Server 2003 (KB979687) 1
Security Update for Windows Server 2003 (KB979907) 1
Security Update for Windows Server 2003 (KB980218) 1
Security Update for Windows Server 2003 (KB981350) 1
Security Update for Windows Server 2003 (KB981957) 1
Security Update for Windows Server 2003 (KB982666) 1
Security Update for Windows Server 2003 (KB982802) 1
Update for Microsoft .NET Framework 3.5 SP1 (KB963707) 1
Update for Microsoft Office 2007 Help for Common Features (KB963673)
Update for Microsoft Office Access 2007 Help (KB963663)
Update for Microsoft Office Excel 2007 Help (KB963678)
Update for Microsoft Office Infopath 2007 Help (KB963662)
Update for Microsoft Office Outlook 2007 Help (KB963677)
Update for Microsoft Office Powerpoint 2007 Help (KB963669)
Update for Microsoft Office Publisher 2007 Help (KB963667)
Update for Microsoft Office Script Editor Help (KB963671)
Update for Microsoft Office Word 2007 Help (KB963665)
Update for Outlook 2007 Junk Email Filter (KB2596560)
Update for Windows Server 2003 (KB2141007) 1
Update for Windows Server 2003 (KB2345886) 1
Update for Windows Server 2003 (KB2388210) 1
Update for Windows Server 2003 (KB2467659) 1
Update for Windows Server 2003 (KB2492386) 1
Update for Windows Server 2003 (KB2607712) 1
Update for Windows Server 2003 (KB2616676-v2) 2
Update for Windows Server 2003 (KB2641690-v2) 2
Update for Windows Server 2003 (KB955759) 1
Update for Windows Server 2003 (KB968389) 1
Update for Windows Server 2003 (KB971029) 1
Update for Windows Server 2003 (KB971737) 1
Update for Windows Server 2003 (KB973687) 1
Update for Windows Server 2003 (KB973917) 1
Update for Windows Server 2003 (KB973917-v2) 2
Update for Windows Server 2003 (KB976749) 1
Update for Windows Server 2003 (KB977165) 1

I don't immediately know of an easy way to determine that.

I don't immediately know of an easy way to determine that.

Well I do appreciate your time. I just figured I would get some feelers out there see if anyone else knows something that I don’t. Here I come needle in the haystack.

http://www.microsoft.com/download/en/search.aspx?q=KB976098

Well, if you want to turn this back in to a programming thing, you can write some code to go through the list using the link above (changing suffix to the KB number), then grab the text in one spot where you can skim it easily :D

Awesome. This help me narrow some of the updates down to a reasonable amount. Having a list like that I was overwelemed. Now to right and see which is which.

Installed all of the updates and the regex.replace() started working correctly. Wish I knew the updates that fix the issue. The site provided helped me pull leverage with the server admins.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.