Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005

    Unanswered: setting the properties of udl file by script

    I am creating udl files by a script for all our websites.Now I have stucked at one point.I am wondering how can i set the properties of udl file by script.
    I need to specify the following properties for the script and place it after
    'set properties of udl

    DRIVER=SQL Server;;UID=login;PWD=pwd;APP =Microsoft® Windows® Operating System;
    user name=login
    initial catalog=db


    Dim objFSO1,objFSO2,fsobj
    set fsobj = server.CreateObject("Scripting.FileSystemObject")
    set getfsobj = fsobj.OpenTextFile("E:\TEST\testing.txt")

    while not getfsobj.AtEndOfStream
    line = getfsobj.ReadLine
    line = split(line,":")
    name = trim(line(0))


    'Set objFSO1 = server.CreateObject("Scripting.FileSystemObject")
    'Set objFSO1=Nothing

    Set objFSO2 = Server.CreateObject("Scripting.FileSystemObject")
    objFSO2.CopyFile "E:\test\temp.udl", "path&name&"\"&udl&"\"&udlname&.udl"
    Set objFSO2 = Nothing

    'set properties of udl

    var=var &" | " &name


  2. #2
    Join Date
    Nov 2003
    Christchurch, New Zealand
    effectively you are just writting a text file yeah? it might have a different extension (.udl) but it is just plan text.

    So why can't you read in the file (similar to what you are doing). Find the properties you want to change. Replace them and write them back out.

    Effectively your file is a collection of value pairs eg X=123;Y=345;Z=234

    So I would do something like this.... read in each line and add for each line split it on the semi colon to get your value pairs, then split each value pair on the equals sign to get a name and a value. If the name is one of the ones you want to replace change the value. Then rewrite the line based on the new value pairs....
       Dim fso, f1, ts, s
       Const ForReading = 1
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set orginalTS = fso.OpenTextFile("c:\orgfile.udl", ForReading)
       Set newTS = fso.CreateTextFile("c:\newfile.udl", true)
       do while orginalLine<>""
          newLine = ""
          valuePairs = split(orginalLine,";")
          for i = 0 to valuePairs.UBound   ' might need ubound-1
              pair = split(valuePairs(i),"=")
              if pair.Ubound = 2 then  ' we have a valid value pair to check
                 name = UCase(pair(0))
                 namevalue = pair(1)
                 if name = PROVIDER" then
                     pair(1) = newProvider
                 end if
                 valuePairs(i) = pair(0) & "=" & pair(1)
              end if
              newLine = newLine & valuePairs(i)
          orginalLine = orginalTS .ReadLine
       orginalTS .Close
       newTS .Close
       Set fso = nothing
       Set orginalTS = nothing
       Set newTS = nothing
    That should be pretty close I think.... I haven't tested it at all. There are a couple of comments there that you might want to check on. The area I have bolded is where you would add the other names of value pairs to replace. You could use a case statement here if you wanted.
    Last edited by rokslide; 09-29-05 at 19:55.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts