473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to Write a UDL File

Hello,

I have been searching for hours and can find no help on this.

I need to programmatically write a UDL file for a only Delphi Application to
use (my program is a launcher).

I was able to do this in Delphi but for the life of me I cant do it in c# -
any help would be appreciated

I have copied my Delphi and C# code below.

When I look in a Hex editor, it is so close - but something is just out.
In Delphi the first hex values are
ff fe

and in C# they come out as

b4 02 fe ff 00

After that it all seems to be the same.

C# Code - Doesnt Work
public void WriteOutUDL()
{
//ReturnUDL has the UDL Alias from the LocalDatabases - write it
out to the .udl file Candle.udl
string buffer = "";
FileStream fs = new FileStream(CRISLauncherLib.UDL_FILE_NAME,
FileMode.Create, FileAccess.Write);
BinaryWriter br = new BinaryWriter(fs,
Encoding.BigEndianUnicode);

buffer = CON_UDL_LINE1 + Environment.NewLine + CON_UDL_LINE2 +
Environment.NewLine;
buffer +=
GetConnectionString(((LoginRecord)CRISLauncherLib. LocalConnections[CRISLauncherLib.ReturnUDL]));
buffer = (char)65279 + buffer + Environment.NewLine;
br.Write(buffer);
br.Close();
fs.Close();
}

____________________________________________
Delphi Code

procedure UpdateUDLFile(sFilename, sConnectionString : String);
var
fsOutput : TFileStream;
sANSIOutput : String;
Buffer : PWideChar;
iBufferSize : Integer;
begin
fsOutput := TFileStream.Create(sFilename, fmCreate);
try { ..Finally }
sANSIOutput := '[oledb]' + #13#10 +
'; Everything after this line is an OLE DB
initstring' + #13#10 +
sConnectionString + #13#10;
iBufferSize := (Length(sANSIOutput) + 2) * 2;
Buffer := AllocMem(iBufferSize);
try { ..Finally }
StringToWideChar(sANSIOutput, Buffer + 1, iBufferSize - 2);
Buffer[0] := #65279;
fsOutput.Write(Buffer^, iBufferSize - 2);
finally
FreeMem(Buffer, iBufferSize);
end; { Try..Finally }
finally
fsOutput.Free;
end; { Try..Finally }
end; { End of UpdateUDLFile. }
Nov 6 '07 #1
3 4139

see: http://msdn2.microsoft.com/en-us/lib...1e(VS.71).aspx

as far as I know the first two bytes are hex FF FE and the remaining content
is string.
Nov 6 '07 #2
thanks for the link
I have all that already
but I cant seem to get it correct.

Dan

"AA2e72E" <AA*****@discussions.microsoft.comwrote in message
news:E5**********************************@microsof t.com...
>
see: http://msdn2.microsoft.com/en-us/lib...1e(VS.71).aspx

as far as I know the first two bytes are hex FF FE and the remaining
content
is string.
Nov 6 '07 #3
got it
public static byte[] StrToByteArray(string str)
{
System.Text.UnicodeEncoding encoding = new
System.Text.UnicodeEncoding();
return encoding.GetBytes(str);
}

public void WriteOutUDL()
{
//ReturnUDL has the UDL Alias from the LocalDatabases - write it
out to the .udl file Candle.udl
string buffer = "";
byte[] output;

FileStream fs = new FileStream(CRISLauncherLib.UDL_FILE_NAME,
FileMode.Create, FileAccess.Write);

buffer = CON_UDL_LINE1 + Environment.NewLine + CON_UDL_LINE2 +
Environment.NewLine;
buffer +=
GetConnectionString(((LoginRecord)CRISLauncherLib. LocalConnections[CRISLauncherLib.ReturnUDL]));
buffer = (char)65279 + buffer + Environment.NewLine;
output = StrToByteArray(buffer);

fs.Write(output, 0, output.Length);
fs.Flush();
fs.Close();
}

"Daniel Jeffrey" <da**************@hotmail.comwrote in message
news:ee**************@TK2MSFTNGP04.phx.gbl...
thanks for the link
I have all that already
but I cant seem to get it correct.

Dan

"AA2e72E" <AA*****@discussions.microsoft.comwrote in message
news:E5**********************************@microsof t.com...
>>
see: http://msdn2.microsoft.com/en-us/lib...1e(VS.71).aspx

as far as I know the first two bytes are hex FF FE and the remaining
content
is string.
Nov 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ellixis | last post by:
Hello, How can I use fwrite() and fseek() in order to write data in the middle (or anywhere else) of a file without overwriting existing data ? People told me that I should load the file into...
5
by: Just Me | last post by:
Using streams how do I write and then read a set of variables? For example, suppose I want to write into a text file: string1,string2,string3 Then read them later. Suppose I want to write...
6
by: sambuela | last post by:
How can I write message to the file located in the wwwroot directory? It seems that IIS protect these files. Let make me cannot do the I/O writing sucessfully. I try to open file's write...
2
by: ykgoh | last post by:
Hi. I've a problem of being able to create and remove a directory but unable to write a file inside the created directory for some strange reason. I suspect that this problem could be vaguely...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
1
by: =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?= | last post by:
Hello All, Our application write logs to a file in a folder. Before our application starts writing to that file, I want to check if the current user has write access to that file, for example,...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
6
by: globalrev | last post by:
i ahve a program that takes certain textsnippets out of one file and inserts them into another. problem is it jsut overwrites the first riow every time. i want to insert every new piece of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.