VB Script to modify tnsnames.ora file

Home Forums Scripting General Scripting VB Script to modify tnsnames.ora file

This topic contains 6 replies, has 3 voices, and was last updated by CaTBuS CaTBuS 10 years, 12 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • CaTBuS
    CaTBuS
    Participant
    #134585

    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 :-D

    Rems
    Rems
    Moderator
    #226993

    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/scriptcenter/guide/sas_scr_hujq.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

    CaTBuS
    CaTBuS
    Participant
    #309104

    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.

    Rems
    Rems
    Moderator
    #226994

    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

    CaTBuS
    CaTBuS
    Participant
    #309105

    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.:beer:

    Avatar
    Dumber
    Participant
    #198098

    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 :)

    Rems
    Rems
    Moderator
    #226998

    Re: VB Script to modify tnsnames.ora file

    Dumber;119294 wrote:
    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

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Register for this Petri Webinar!

Software-Defined Unlimited Backup Storage

Tuesday, August 27, 2019 @ 1:00 pm EDT

A Scale-Out Backup storage infrastructure is a must-have technology for your backups. In this webinar, join expert Rick Vanover for a look on what real-world problems are solved by the Scale-Out Backup Repository.

Register Now

Sponsored By