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