If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > setting the properties of udl file by script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-20-05, 09:44
softtycoon softtycoon is offline
Registered User
 
Join Date: Sep 2005
Posts: 4
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


provider=sqloledb
DRIVER=SQL Server;SERVER=xxx.xxx.xx.xxx;UID=login;PWD=pwd;APP =Microsoft® Windows® Operating System;
user name=login
password=pwd
initial catalog=db
accesspermisson=read


<%


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))
type=trim(line(4))
db=trim(line(5))
login=trim(line(6))
pwd=trim(line(7))
udlname=trim(line(8))
Path="D\DATA\"

udl=udl

'Set objFSO1 = server.CreateObject("Scripting.FileSystemObject")
'objFSO1.CreateFolder(Path&name&"\"&udl)
'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
wend

%>
Reply With Quote
  #2 (permalink)  
Old 09-29-05, 19:53
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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....
Code:
   newProvider="sqloledb"

   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)

      next

      newTS.WriteLine(newLine)
      orginalLine = orginalTS .ReadLine
   loop

   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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On