Hi All.

I have a very basic doubt.
How, in the name of GOD, I create a UDL file that works, using
vbScript?!

I've been trying to accomplish that usign FileSystemObject with no
success...

Thanks in advance!!

Rodolfo
Sao Paulo - BR

Re: UDL File by Scott

Scott
Tue Nov 30 10:35:04 CST 2004

It would be helpful if you could post the contents (scrubbed of sensitive
information, of course) of the UDL file you wind up with and what error it
is generating when you try to use it.
--
Scott Fenstermacher
Network Engineer
Levi, Ray and Shoup, INC

"Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
news:uAs04Uu1EHA.1264@TK2MSFTNGP12.phx.gbl...
> Hi All.
>
> I have a very basic doubt.
> How, in the name of GOD, I create a UDL file that works, using
> vbScript?!
>
> I've been trying to accomplish that usign FileSystemObject with no
> success...
>
> Thanks in advance!!
>
> Rodolfo
> Sao Paulo - BR
>



Re: UDL File by Rodolfo

Rodolfo
Tue Nov 30 11:10:40 CST 2004

Hi Scott

As I could see, UDL file is like a text file. If i edit UDL file in a
notepad, I can see the connection string and other thing that configure that
file as a UDL one.

So, I tried to create a UDL file just like a text file and
FileSystemObejct created it. But when I try to connect to my database
through this UDL file, but this retrieves me an error.

Here comes the code:
Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\teste.udl", True)
tf.WriteLine("[oledb]")
tf.WriteLine("; Everything after this line is an OLE DB initstring")
tf.WriteLine("Provider=SQLOLEDB.1;Password=pwd;Persist Security
Info=True;User ID=user;Initial Catalog=master;Data Source=DATABASE")

tf.Close


Thanks a lot
Rodolfo
Sao Paulo - BR



"Scott Fenstermacher" <sfenstermacher@lrs.com> wrote in message
news:%23KxCGqv1EHA.1292@TK2MSFTNGP10.phx.gbl...
> It would be helpful if you could post the contents (scrubbed of sensitive
> information, of course) of the UDL file you wind up with and what error it
> is generating when you try to use it.
> --
> Scott Fenstermacher
> Network Engineer
> Levi, Ray and Shoup, INC
>
> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
> news:uAs04Uu1EHA.1264@TK2MSFTNGP12.phx.gbl...
>> Hi All.
>>
>> I have a very basic doubt.
>> How, in the name of GOD, I create a UDL file that works, using
>> vbScript?!
>>
>> I've been trying to accomplish that usign FileSystemObject with no
>> success...
>>
>> Thanks in advance!!
>>
>> Rodolfo
>> Sao Paulo - BR
>>
>
>



Re: UDL File by Rodolfo

Rodolfo
Tue Nov 30 12:46:59 CST 2004

Another code i have already tried, but this one in VB6.
This code creates the "test.udl file", but I can't open this file because
file system is saing that is not a Data Link valid file.


Dim StrContent As String

Dim Strm As New ADODB.Stream
Strm.Type = adTypeBinary
Strm.Open

StrContent = "[oledb]" & vbCrLf
arrByte = StrConv(StrContent, vbFromUnicode)
Strm.Write arrByte

StrContent = "; Everything after this line is an OLE DB initstring" &
vbCrLf
arrByte = StrConv(StrContent, vbFromUnicode)
Strm.Write arrByte

StrContent = "Provider=SQLOLEDB.1;Password=pwd;Persist Security
Info=True;User ID=user;Initial Catalog=master;Data Source=server" & vbCrLf
arrByte = StrConv(StrContent, vbFromUnicode)
Strm.Write arrByte

Strm.SaveToFile "c:\test.udl", adSaveCreateOverWrite
Strm.Flush
Strm.Close

End




"Scott Fenstermacher" <sfenstermacher@lrs.com> wrote in message
news:%23KxCGqv1EHA.1292@TK2MSFTNGP10.phx.gbl...
> It would be helpful if you could post the contents (scrubbed of sensitive
> information, of course) of the UDL file you wind up with and what error it
> is generating when you try to use it.
> --
> Scott Fenstermacher
> Network Engineer
> Levi, Ray and Shoup, INC
>
> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
> news:uAs04Uu1EHA.1264@TK2MSFTNGP12.phx.gbl...
>> Hi All.
>>
>> I have a very basic doubt.
>> How, in the name of GOD, I create a UDL file that works, using
>> vbScript?!
>>
>> I've been trying to accomplish that usign FileSystemObject with no
>> success...
>>
>> Thanks in advance!!
>>
>> Rodolfo
>> Sao Paulo - BR
>>
>
>



Re: UDL File by Rodolfo

Rodolfo
Wed Dec 01 07:24:36 CST 2004

Scott

I've found in other code block that I MUST write in the first line of
UDL file the short value &HFEFFS
My big problem now is, how I write this in de UDL file usign VB.


Thanks a lot

Rodolfo Alves Roim
Sao Paulo - BR




"Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
news:uLiG8zw1EHA.1524@TK2MSFTNGP09.phx.gbl...
> Another code i have already tried, but this one in VB6.
> This code creates the "test.udl file", but I can't open this file because
> file system is saing that is not a Data Link valid file.
>
>
> Dim StrContent As String
>
> Dim Strm As New ADODB.Stream
> Strm.Type = adTypeBinary
> Strm.Open
>
> StrContent = "[oledb]" & vbCrLf
> arrByte = StrConv(StrContent, vbFromUnicode)
> Strm.Write arrByte
>
> StrContent = "; Everything after this line is an OLE DB initstring" &
> vbCrLf
> arrByte = StrConv(StrContent, vbFromUnicode)
> Strm.Write arrByte
>
> StrContent = "Provider=SQLOLEDB.1;Password=pwd;Persist Security
> Info=True;User ID=user;Initial Catalog=master;Data Source=server" & vbCrLf
> arrByte = StrConv(StrContent, vbFromUnicode)
> Strm.Write arrByte
>
> Strm.SaveToFile "c:\test.udl", adSaveCreateOverWrite
> Strm.Flush
> Strm.Close
>
> End
>
>
>
>
> "Scott Fenstermacher" <sfenstermacher@lrs.com> wrote in message
> news:%23KxCGqv1EHA.1292@TK2MSFTNGP10.phx.gbl...
>> It would be helpful if you could post the contents (scrubbed of sensitive
>> information, of course) of the UDL file you wind up with and what error
>> it is generating when you try to use it.
>> --
>> Scott Fenstermacher
>> Network Engineer
>> Levi, Ray and Shoup, INC
>>
>> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
>> news:uAs04Uu1EHA.1264@TK2MSFTNGP12.phx.gbl...
>>> Hi All.
>>>
>>> I have a very basic doubt.
>>> How, in the name of GOD, I create a UDL file that works, using
>>> vbScript?!
>>>
>>> I've been trying to accomplish that usign FileSystemObject with no
>>> success...
>>>
>>> Thanks in advance!!
>>>
>>> Rodolfo
>>> Sao Paulo - BR
>>>
>>
>>
>
>



Re: UDL File by Thorsten

Thorsten
Wed Dec 01 08:48:56 CST 2004

Hi Rodolfo,

A UDL File is not a plain text file.
And the difference is much more than setting the first bytes to FFFE.
Let's have a look to an udl file with an hex editor:
FF FE 5B 00 6F 00 6C 00 65 00 64 00 62 00 5D 00; ÿþ[.o.l.e.d.b.].
The same part if you generate it via fso:
FF FE 5B 6F 6C 65 64 62 5D 0D 0A 3B 20 45 76 65 72 79; [oledb]..; Every
There is a "00" between every character.

I tried it some time ago, but never was able to generate a UDL file with
vbs. Sorry, but I think vbs is a dead end for this problem...


"Rodolfo Roim" <rodolfo@k2m.com.br> schrieb im Newsbeitrag
news:ewBPek61EHA.2196@TK2MSFTNGP14.phx.gbl...
> Scott
>
> I've found in other code block that I MUST write in the first line of
> UDL file the short value &HFEFFS
> My big problem now is, how I write this in de UDL file usign VB.
>
>
> Thanks a lot
>
> Rodolfo Alves Roim
> Sao Paulo - BR
>
>
>
>
> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
> news:uLiG8zw1EHA.1524@TK2MSFTNGP09.phx.gbl...
>> Another code i have already tried, but this one in VB6.
>> This code creates the "test.udl file", but I can't open this file because
>> file system is saing that is not a Data Link valid file.
>>
>>
>> Dim StrContent As String
>>
>> Dim Strm As New ADODB.Stream
>> Strm.Type = adTypeBinary
>> Strm.Open
>>
>> StrContent = "[oledb]" & vbCrLf
>> arrByte = StrConv(StrContent, vbFromUnicode)
>> Strm.Write arrByte
>>
>> StrContent = "; Everything after this line is an OLE DB initstring" &
>> vbCrLf
>> arrByte = StrConv(StrContent, vbFromUnicode)
>> Strm.Write arrByte
>>
>> StrContent = "Provider=SQLOLEDB.1;Password=pwd;Persist Security
>> Info=True;User ID=user;Initial Catalog=master;Data Source=server" &
>> vbCrLf
>> arrByte = StrConv(StrContent, vbFromUnicode)
>> Strm.Write arrByte
>>
>> Strm.SaveToFile "c:\test.udl", adSaveCreateOverWrite
>> Strm.Flush
>> Strm.Close
>>
>> End
>>
>>
>>
>>
>> "Scott Fenstermacher" <sfenstermacher@lrs.com> wrote in message
>> news:%23KxCGqv1EHA.1292@TK2MSFTNGP10.phx.gbl...
>>> It would be helpful if you could post the contents (scrubbed of
>>> sensitive information, of course) of the UDL file you wind up with and
>>> what error it is generating when you try to use it.
>>> --
>>> Scott Fenstermacher
>>> Network Engineer
>>> Levi, Ray and Shoup, INC
>>>
>>> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
>>> news:uAs04Uu1EHA.1264@TK2MSFTNGP12.phx.gbl...
>>>> Hi All.
>>>>
>>>> I have a very basic doubt.
>>>> How, in the name of GOD, I create a UDL file that works, using
>>>> vbScript?!
>>>>
>>>> I've been trying to accomplish that usign FileSystemObject with no
>>>> success...
>>>>
>>>> Thanks in advance!!
>>>>
>>>> Rodolfo
>>>> Sao Paulo - BR
>>>>
>>>
>>>
>>
>>
>
>



Re: UDL File by Joe

Joe
Wed Dec 01 10:19:58 CST 2004

"Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
news:uivqI%23v1EHA.1404@TK2MSFTNGP11.phx.gbl...
> Hi Scott
>
> As I could see, UDL file is like a text file. If i edit UDL file in a
> notepad, I can see the connection string and other thing that configure
> that file as a UDL one.
>
> So, I tried to create a UDL file just like a text file and
> FileSystemObejct created it. But when I try to connect to my database
> through this UDL file, but this retrieves me an error.
>
> Here comes the code:
> Dim fso, tf
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set tf = fso.CreateTextFile("c:\teste.udl", True)
> tf.WriteLine("[oledb]")
> tf.WriteLine("; Everything after this line is an OLE DB initstring")
> tf.WriteLine("Provider=SQLOLEDB.1;Password=pwd;Persist Security
> Info=True;User ID=user;Initial Catalog=master;Data Source=DATABASE")
>
> tf.Close
>
>
> Thanks a lot
> Rodolfo
> Sao Paulo - BR
>
>
>
Perhaps it wants a unicode file?
Set tf = fso.CreateTextFile("c:\teste.udl", True, True)

--

Joe (MVP)



Re: UDL File by Rodolfo

Rodolfo
Wed Dec 01 10:51:53 CST 2004

Hi Thorsten

I'm affraid so.
But I have a VB.NET code that generates a UDL file that really works.

Here it goes:


Dim arrConteudo() As Byte
Dim strAuxiliar As String
Dim Gravador As New BinaryWriter(strmArquivo)

Gravador.Write(&HFEFFS)
strAuxiliar = "[oledb]" & vbCrLf
ReDim arrConteudo(strAuxiliar.Length * 2)
arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
Gravador.Write(arrConteudo)
strAuxiliar = "; Everything after this line is an OLE DB initstring" &
vbCrLf
ReDim arrConteudo(strAuxiliar.Length * 2)
arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
Gravador.Write(arrConteudo)

strAuxiliar = "Provider=SQLOLEDB.1;Password=" & _
_Senha & _
";Persist Security Info=True;User ID=" & _
_Usuario & _
";Initial Catalog=" & _
_NomeDoBancoDeDados & _
";Data Source=" & _
_NomeDoServidor & _
vbCrLf

ReDim arrConteudo(strAuxiliar.Length * 2)
arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
Gravador.Write(arrConteudo)
Gravador.Flush()
Gravador.Close()
Gravador = Nothing
strmArquivo = Nothing

The deffernece of this code to mine is "Gravador.Write(&HFEFFS)"
So I assume that this "thing" (&HFEFFS) is responsible right creating os
UDL file.

What do you think about it?

thanks a lot

Rodolfo Alves Roim
Sao Paulo - BR

"Thorsten Helfer" <thorsten.helfer@it-helfer.de> wrote in message
news:uDsQiT71EHA.3816@TK2MSFTNGP09.phx.gbl...
> Hi Rodolfo,
>
> A UDL File is not a plain text file.
> And the difference is much more than setting the first bytes to FFFE.
> Let's have a look to an udl file with an hex editor:
> FF FE 5B 00 6F 00 6C 00 65 00 64 00 62 00 5D 00; ÿþ[.o.l.e.d.b.].
> The same part if you generate it via fso:
> FF FE 5B 6F 6C 65 64 62 5D 0D 0A 3B 20 45 76 65 72 79; [oledb]..; Every
> There is a "00" between every character.
>
> I tried it some time ago, but never was able to generate a UDL file with
> vbs. Sorry, but I think vbs is a dead end for this problem...
>
>
> "Rodolfo Roim" <rodolfo@k2m.com.br> schrieb im Newsbeitrag
> news:ewBPek61EHA.2196@TK2MSFTNGP14.phx.gbl...
>> Scott
>>
>> I've found in other code block that I MUST write in the first line of
>> UDL file the short value &HFEFFS
>> My big problem now is, how I write this in de UDL file usign VB.
>>
>>
>> Thanks a lot
>>
>> Rodolfo Alves Roim
>> Sao Paulo - BR
>>
>>
>>
>>
>> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
>> news:uLiG8zw1EHA.1524@TK2MSFTNGP09.phx.gbl...
>>> Another code i have already tried, but this one in VB6.
>>> This code creates the "test.udl file", but I can't open this file
>>> because file system is saing that is not a Data Link valid file.
>>>
>>>
>>> Dim StrContent As String
>>>
>>> Dim Strm As New ADODB.Stream
>>> Strm.Type = adTypeBinary
>>> Strm.Open
>>>
>>> StrContent = "[oledb]" & vbCrLf
>>> arrByte = StrConv(StrContent, vbFromUnicode)
>>> Strm.Write arrByte
>>>
>>> StrContent = "; Everything after this line is an OLE DB initstring" &
>>> vbCrLf
>>> arrByte = StrConv(StrContent, vbFromUnicode)
>>> Strm.Write arrByte
>>>
>>> StrContent = "Provider=SQLOLEDB.1;Password=pwd;Persist Security
>>> Info=True;User ID=user;Initial Catalog=master;Data Source=server" &
>>> vbCrLf
>>> arrByte = StrConv(StrContent, vbFromUnicode)
>>> Strm.Write arrByte
>>>
>>> Strm.SaveToFile "c:\test.udl", adSaveCreateOverWrite
>>> Strm.Flush
>>> Strm.Close
>>>
>>> End
>>>
>>>
>>>
>>>
>>> "Scott Fenstermacher" <sfenstermacher@lrs.com> wrote in message
>>> news:%23KxCGqv1EHA.1292@TK2MSFTNGP10.phx.gbl...
>>>> It would be helpful if you could post the contents (scrubbed of
>>>> sensitive information, of course) of the UDL file you wind up with and
>>>> what error it is generating when you try to use it.
>>>> --
>>>> Scott Fenstermacher
>>>> Network Engineer
>>>> Levi, Ray and Shoup, INC
>>>>
>>>> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
>>>> news:uAs04Uu1EHA.1264@TK2MSFTNGP12.phx.gbl...
>>>>> Hi All.
>>>>>
>>>>> I have a very basic doubt.
>>>>> How, in the name of GOD, I create a UDL file that works, using
>>>>> vbScript?!
>>>>>
>>>>> I've been trying to accomplish that usign FileSystemObject with no
>>>>> success...
>>>>>
>>>>> Thanks in advance!!
>>>>>
>>>>> Rodolfo
>>>>> Sao Paulo - BR
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Re: UDL File by Thorsten

Thorsten
Wed Dec 01 12:12:54 CST 2004

Cool stuff!
Thanks for posting!


"Rodolfo Roim" <rodolfo@k2m.com.br> schrieb im Newsbeitrag
news:OwIMRY81EHA.2196@TK2MSFTNGP14.phx.gbl...
> Hi Thorsten
>
> I'm affraid so.
> But I have a VB.NET code that generates a UDL file that really works.
>
> Here it goes:
>
>
> Dim arrConteudo() As Byte
> Dim strAuxiliar As String
> Dim Gravador As New BinaryWriter(strmArquivo)
>
> Gravador.Write(&HFEFFS)
> strAuxiliar = "[oledb]" & vbCrLf
> ReDim arrConteudo(strAuxiliar.Length * 2)
> arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
> Gravador.Write(arrConteudo)
> strAuxiliar = "; Everything after this line is an OLE DB initstring" &
> vbCrLf
> ReDim arrConteudo(strAuxiliar.Length * 2)
> arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
> Gravador.Write(arrConteudo)
>
> strAuxiliar = "Provider=SQLOLEDB.1;Password=" & _
> _Senha & _
> ";Persist Security Info=True;User ID=" & _
> _Usuario & _
> ";Initial Catalog=" & _
> _NomeDoBancoDeDados & _
> ";Data Source=" & _
> _NomeDoServidor & _
> vbCrLf
>
> ReDim arrConteudo(strAuxiliar.Length * 2)
> arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
> Gravador.Write(arrConteudo)
> Gravador.Flush()
> Gravador.Close()
> Gravador = Nothing
> strmArquivo = Nothing
>
> The deffernece of this code to mine is "Gravador.Write(&HFEFFS)"
> So I assume that this "thing" (&HFEFFS) is responsible right creating os
> UDL file.
>
> What do you think about it?
>
> thanks a lot
>
> Rodolfo Alves Roim
> Sao Paulo - BR
>
> "Thorsten Helfer" <thorsten.helfer@it-helfer.de> wrote in message
> news:uDsQiT71EHA.3816@TK2MSFTNGP09.phx.gbl...
>> Hi Rodolfo,
>>
>> A UDL File is not a plain text file.
>> And the difference is much more than setting the first bytes to FFFE.
>> Let's have a look to an udl file with an hex editor:
>> FF FE 5B 00 6F 00 6C 00 65 00 64 00 62 00 5D 00; ÿþ[.o.l.e.d.b.].
>> The same part if you generate it via fso:
>> FF FE 5B 6F 6C 65 64 62 5D 0D 0A 3B 20 45 76 65 72 79; [oledb]..; Every
>> There is a "00" between every character.
>>
>> I tried it some time ago, but never was able to generate a UDL file with
>> vbs. Sorry, but I think vbs is a dead end for this problem...
>>
>>
>> "Rodolfo Roim" <rodolfo@k2m.com.br> schrieb im Newsbeitrag
>> news:ewBPek61EHA.2196@TK2MSFTNGP14.phx.gbl...
>>> Scott
>>>
>>> I've found in other code block that I MUST write in the first line of
>>> UDL file the short value &HFEFFS
>>> My big problem now is, how I write this in de UDL file usign VB.
>>>
>>>
>>> Thanks a lot
>>>
>>> Rodolfo Alves Roim
>>> Sao Paulo - BR
>>>
>>>
>>>
>>>
>>> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
>>> news:uLiG8zw1EHA.1524@TK2MSFTNGP09.phx.gbl...
>>>> Another code i have already tried, but this one in VB6.
>>>> This code creates the "test.udl file", but I can't open this file
>>>> because file system is saing that is not a Data Link valid file.
>>>>
>>>>
>>>> Dim StrContent As String
>>>>
>>>> Dim Strm As New ADODB.Stream
>>>> Strm.Type = adTypeBinary
>>>> Strm.Open
>>>>
>>>> StrContent = "[oledb]" & vbCrLf
>>>> arrByte = StrConv(StrContent, vbFromUnicode)
>>>> Strm.Write arrByte
>>>>
>>>> StrContent = "; Everything after this line is an OLE DB initstring"
>>>> & vbCrLf
>>>> arrByte = StrConv(StrContent, vbFromUnicode)
>>>> Strm.Write arrByte
>>>>
>>>> StrContent = "Provider=SQLOLEDB.1;Password=pwd;Persist Security
>>>> Info=True;User ID=user;Initial Catalog=master;Data Source=server" &
>>>> vbCrLf
>>>> arrByte = StrConv(StrContent, vbFromUnicode)
>>>> Strm.Write arrByte
>>>>
>>>> Strm.SaveToFile "c:\test.udl", adSaveCreateOverWrite
>>>> Strm.Flush
>>>> Strm.Close
>>>>
>>>> End
>>>>
>>>>
>>>>
>>>>
>>>> "Scott Fenstermacher" <sfenstermacher@lrs.com> wrote in message
>>>> news:%23KxCGqv1EHA.1292@TK2MSFTNGP10.phx.gbl...
>>>>> It would be helpful if you could post the contents (scrubbed of
>>>>> sensitive information, of course) of the UDL file you wind up with and
>>>>> what error it is generating when you try to use it.
>>>>> --
>>>>> Scott Fenstermacher
>>>>> Network Engineer
>>>>> Levi, Ray and Shoup, INC
>>>>>
>>>>> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
>>>>> news:uAs04Uu1EHA.1264@TK2MSFTNGP12.phx.gbl...
>>>>>> Hi All.
>>>>>>
>>>>>> I have a very basic doubt.
>>>>>> How, in the name of GOD, I create a UDL file that works, using
>>>>>> vbScript?!
>>>>>>
>>>>>> I've been trying to accomplish that usign FileSystemObject with no
>>>>>> success...
>>>>>>
>>>>>> Thanks in advance!!
>>>>>>
>>>>>> Rodolfo
>>>>>> Sao Paulo - BR
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Re: UDL File by Michael

Michael
Wed Dec 01 20:15:41 CST 2004

> A UDL File is not a plain text file.
> And the difference is much more than setting the first bytes to FFFE.
> Let's have a look to an udl file with an hex editor:
> FF FE 5B 00 6F 00 6C 00 65 00 64 00 62 00 5D 00; ÿþ[.o.l.e.d.b.].
> The same part if you generate it via fso:
> FF FE 5B 6F 6C 65 64 62 5D 0D 0A 3B 20 45 76 65 72 79; [oledb]..;
> Every There is a "00" between every character.

A clear indication that it is a Unicode file...

>
> I tried it some time ago, but never was able to generate a UDL file
> with vbs. Sorry, but I think vbs is a dead end for this problem...

See Joe Fawcett's reply on this thread.

--
Michael Harris
Microsoft MVP Scripting



Re: UDL File by antongil

antongil
Thu Jan 13 00:43:02 CST 2005

Not sure if it is too late to help you, but I thought I would respond anyway.
This works for me every time.

Just to let anyone know....

I have found the solution to the .udl problem. As stated, I wanted to be
able to link to various Access DB by updating using a .udl file. I am using a
Dialog box to update the location of the file. Once I have completed my
search and click "ok" the following code updates my .udl file and the next
time I open the program it goes to the last database I selected. all of my
connections strings in code read: Conn1.Open "File Name=c:\nep.udl". All my
ADODC connection strings simply read: "File Name=c:\nep.udl"

Below is the code that overwrites the nep.udl file. I put the file on my c
drive as I will do during setup on each of my clients machines. This has been
and extremely helpful tool:

Private Sub cmdLinkNew_Click()
Dim myDB As ADODB.Connection
Dim myRS As ADODB.Recordset
Dim strCnn As String

Dim bReturn As Boolean
Dim bByteOutput() As Byte

Dim sTemp As String

Set gblConnection = New ADODB.Connection
If Right(LFile.Path, 1) <> "\" Then ' this is a network conneciton
NameOfFile = LFile.Path + "\" + LFile.FileName
Else
NameOfFile = LFile.Path + LFile.FileName ' this works for a drive connection
End If
Text1 = NameOfFile
gblConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + NameOfFile
+ ";Persist Security Info=False"

Open "C:\NEP.udl" For Binary As #1

Put #1, , &HFEFF

sTemp = "[oledb]" & vbCrLf
bByteOutput = sTemp
Put #1, , bByteOutput

sTemp = "; Everything after this line is an OLE DB initstring" & vbCrLf

ReDim bByteOutput(Len(sTemp) * 2) As Byte
bByteOutput = sTemp
Put #1, , bByteOutput

ReDim bByteOutput(Len(gblConnection & vbCrLf) * 2) As Byte
bByteOutput = gblConnection & vbCrLf
Put #1, , bByteOutput

Close #1

Main.txtPath = gblConnection
Main.Show
Main.Description.Refresh
Unload Me

End Sub


"Rodolfo Roim" wrote:

> Hi Thorsten
>
> I'm affraid so.
> But I have a VB.NET code that generates a UDL file that really works.
>
> Here it goes:
>
>
> Dim arrConteudo() As Byte
> Dim strAuxiliar As String
> Dim Gravador As New BinaryWriter(strmArquivo)
>
> Gravador.Write(&HFEFFS)
> strAuxiliar = "[oledb]" & vbCrLf
> ReDim arrConteudo(strAuxiliar.Length * 2)
> arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
> Gravador.Write(arrConteudo)
> strAuxiliar = "; Everything after this line is an OLE DB initstring" &
> vbCrLf
> ReDim arrConteudo(strAuxiliar.Length * 2)
> arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
> Gravador.Write(arrConteudo)
>
> strAuxiliar = "Provider=SQLOLEDB.1;Password=" & _
> _Senha & _
> ";Persist Security Info=True;User ID=" & _
> _Usuario & _
> ";Initial Catalog=" & _
> _NomeDoBancoDeDados & _
> ";Data Source=" & _
> _NomeDoServidor & _
> vbCrLf
>
> ReDim arrConteudo(strAuxiliar.Length * 2)
> arrConteudo = System.Text.UnicodeEncoding.Unicode.GetBytes(strAuxiliar)
> Gravador.Write(arrConteudo)
> Gravador.Flush()
> Gravador.Close()
> Gravador = Nothing
> strmArquivo = Nothing
>
> The deffernece of this code to mine is "Gravador.Write(&HFEFFS)"
> So I assume that this "thing" (&HFEFFS) is responsible right creating os
> UDL file.
>
> What do you think about it?
>
> thanks a lot
>
> Rodolfo Alves Roim
> Sao Paulo - BR
>
> "Thorsten Helfer" <thorsten.helfer@it-helfer.de> wrote in message
> news:uDsQiT71EHA.3816@TK2MSFTNGP09.phx.gbl...
> > Hi Rodolfo,
> >
> > A UDL File is not a plain text file.
> > And the difference is much more than setting the first bytes to FFFE.
> > Let's have a look to an udl file with an hex editor:
> > FF FE 5B 00 6F 00 6C 00 65 00 64 00 62 00 5D 00; ÿþ[.o.l.e.d.b.].
> > The same part if you generate it via fso:
> > FF FE 5B 6F 6C 65 64 62 5D 0D 0A 3B 20 45 76 65 72 79; [oledb]..; Every
> > There is a "00" between every character.
> >
> > I tried it some time ago, but never was able to generate a UDL file with
> > vbs. Sorry, but I think vbs is a dead end for this problem...
> >
> >
> > "Rodolfo Roim" <rodolfo@k2m.com.br> schrieb im Newsbeitrag
> > news:ewBPek61EHA.2196@TK2MSFTNGP14.phx.gbl...
> >> Scott
> >>
> >> I've found in other code block that I MUST write in the first line of
> >> UDL file the short value &HFEFFS
> >> My big problem now is, how I write this in de UDL file usign VB.
> >>
> >>
> >> Thanks a lot
> >>
> >> Rodolfo Alves Roim
> >> Sao Paulo - BR
> >>
> >>
> >>
> >>
> >> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
> >> news:uLiG8zw1EHA.1524@TK2MSFTNGP09.phx.gbl...
> >>> Another code i have already tried, but this one in VB6.
> >>> This code creates the "test.udl file", but I can't open this file
> >>> because file system is saing that is not a Data Link valid file.
> >>>
> >>>
> >>> Dim StrContent As String
> >>>
> >>> Dim Strm As New ADODB.Stream
> >>> Strm.Type = adTypeBinary
> >>> Strm.Open
> >>>
> >>> StrContent = "[oledb]" & vbCrLf
> >>> arrByte = StrConv(StrContent, vbFromUnicode)
> >>> Strm.Write arrByte
> >>>
> >>> StrContent = "; Everything after this line is an OLE DB initstring" &
> >>> vbCrLf
> >>> arrByte = StrConv(StrContent, vbFromUnicode)
> >>> Strm.Write arrByte
> >>>
> >>> StrContent = "Provider=SQLOLEDB.1;Password=pwd;Persist Security
> >>> Info=True;User ID=user;Initial Catalog=master;Data Source=server" &
> >>> vbCrLf
> >>> arrByte = StrConv(StrContent, vbFromUnicode)
> >>> Strm.Write arrByte
> >>>
> >>> Strm.SaveToFile "c:\test.udl", adSaveCreateOverWrite
> >>> Strm.Flush
> >>> Strm.Close
> >>>
> >>> End
> >>>
> >>>
> >>>
> >>>
> >>> "Scott Fenstermacher" <sfenstermacher@lrs.com> wrote in message
> >>> news:%23KxCGqv1EHA.1292@TK2MSFTNGP10.phx.gbl...
> >>>> It would be helpful if you could post the contents (scrubbed of
> >>>> sensitive information, of course) of the UDL file you wind up with and
> >>>> what error it is generating when you try to use it.
> >>>> --
> >>>> Scott Fenstermacher
> >>>> Network Engineer
> >>>> Levi, Ray and Shoup, INC
> >>>>
> >>>> "Rodolfo Roim" <rodolfo@k2m.com.br> wrote in message
> >>>> news:uAs04Uu1EHA.1264@TK2MSFTNGP12.phx.gbl...
> >>>>> Hi All.
> >>>>>
> >>>>> I have a very basic doubt.
> >>>>> How, in the name of GOD, I create a UDL file that works, using
> >>>>> vbScript?!
> >>>>>
> >>>>> I've been trying to accomplish that usign FileSystemObject with no
> >>>>> success...
> >>>>>
> >>>>> Thanks in advance!!
> >>>>>
> >>>>> Rodolfo
> >>>>> Sao Paulo - BR
> >>>>>
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>
> >
> >
>
>
>