Announcement

Collapse
No announcement yet.

VB Script to modify tnsnames.ora file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB Script to modify tnsnames.ora file

    I am creating an SMS package to deploy a TPT upgrade. This upgrade will require an amendment to the tnsnames.ora file (can be edited via notepad etc) in the way of added lines of text. These lines can be added to the end of the document and don't need to replace any existing text or be added at a particular place. Any help would be appreciated.

    Thank you in advance for saving my can again, one question at a time

  • #2
    Re: VB Script to modify tnsnames.ora file

    Google for: OpenTextFile ForAppending
    you will find script samples.

    "Write" or "Writeline" are the FileSystemObject methods you can use to append text.
    http://www.microsoft.com/technet/scr....mspx?mfr=true


    basic code:
    Code:
     
    Const ForAppending = 8
    Const Open_as_Unicode = True
     
    strFolder = "c:\scripts"
    strFile = "test.txt"
    strNewLine = "new text."
     
    strPath = strFolder & "\" & strFile
    Set FSO = CreateObject("Scripting.FileSystemObject")
     
    If (FSO.FileExists(strPath) = True) Then
       Set objFile = FSO.OpenTextFile(strPath, ForAppending, Open_as_Unicode) 
       objFile.Writeline(strNewLine)
       objFile.Close : Set objFile = Nothing
    End If
    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: VB Script to modify tnsnames.ora file

      This is great. I have been playing with this and it will most certainly work. My only question is that this needs to write multiple lines of code in succession. The carriage returns are causing errors. Do I need to create a new object for each line of text? Or is there syntax for multiple lines for one object? Here is a sample of the code:

      strNewLine = "ts1db.world=
      (DESCRIPTION =
      (ADDRESS LIST =
      COMMUNIY = sap.world (and so on and so forth)"

      Thanks again.

      Comment


      • #4
        Re: VB Script to modify tnsnames.ora file

        There are to ways how you can append more than one unique line.

        You can add a LineFeed and Carriage return character at the end of each line to the strNewLine variable:
        Code:
         
        strNewLine = "ts1db.world = " & vbCrLf _
                & "(DESCRIPTION = " & vbCrLf _
                & "(ADDRESS LIST = " & vbCrLf _
                & "COMMUNIY = sap.world" & vbCrLf _
                & "(and so on and so forth)"
        Or you can use multiple times the WriteLine method (no need to create a new object for each line of text):
        Code:
         
        If (FSO.FileExists(strPath) = True) Then
          Set objFile = FSO.OpenTextFile(strPath, ForAppending, Open_as_Unicode) 
          objFile.Writeline("ts1db.world = ")
          objFile.Writeline("(DESCRIPTION = ")
          objFile.Writeline("COMMUNIY = sap.world")
          objFile.Writeline("(and so on and so forth)")
          objFile.Close : Set objFile = Nothing
        End If
        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: VB Script to modify tnsnames.ora file

          Thanks rems! No surprise, your code worked perfectly. I actually found the carriage line feed command and added it as a new line of code. I think my finished product is a good as can be thanks to you. I owe you a beer.

          Comment


          • #6
            Re: VB Script to modify tnsnames.ora file

            I always used chr(13) + chr(10) for a new line instead of vbCrLf...
            it's a long time that I played with scripting
            Marcel
            Technical Consultant
            Netherlands
            http://www.phetios.com
            http://blog.nessus.nl

            MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
            "No matter how secure, there is always the human factor."

            "Enjoy life today, tomorrow may never come."
            "If you're going through hell, keep going. ~Winston Churchill"

            Comment


            • #7
              Re: VB Script to modify tnsnames.ora file

              Originally posted by Dumber View Post
              I always used chr(13) + chr(10) for a new line instead of vbCrLf...
              it's a long time that I played with scripting
              Yes, you can use the Hexadecimal Equivalent in vbscript.

              Note,
              In VBS rather use "&" to group and use the "+" only as an arithmetic operator.

              Chr(13) is the hexadecimal value of the constant vbCr
              Chr(10 is the hexadecimal value of the contstant vbLf
              Chr(13) & Chr(10) is the same as vbCr & vbLf - And can be replaced by the Constant VbCrLf or vbNewLine.

              Reference information on Constants and Enumerations in VB: Print and Display Constants

              \Rems

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment

              Working...
              X