Universal Data Link - File cannot be opened. Make sure it is a valid Link Link file

I am trying to create a UDL file programmatically in C #. In my program, I want to show the user the Data Link properties window, but with my own default values ​​for the connection string. At first I thought of doing the following:

string[] lines = new string[]
{
    "[oledb]",
    "; Everything after this line is an OLE DB initstring",
    "Provider=SQLOLEDB.1;Persist Security Info=False"
};

File.WriteAllLines("Test.udl", lines);
Process p = Process.Start("Test.udl");
p.WaitForExit();

However, I get this error when trying to open a file:

File cannot be opened. Make sure it is a valid Link Link file.

This is strange because I created an empty file, named it something.udl, opened it, clicked OK, and then opened the contents of the file, which was:

[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Persist Security Info=False

. KDiff , , , " , " - .

, , File.WriteAllLines . , . , ?

MSDN UDL. , lines, .

+4
1

, , Unicode:

File.WriteAllLines("Test.udl", lines, Encoding.Unicode);
+1

All Articles