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