c# - Universal Data Link - File cannot be opened. Ensure it is a valid Data Link file -


i attempting create udl file programmatically in c#. in program, want show user data link properties window own default values connection string. thought following:

string[] lines = new string[] {     "[oledb]",     "; after line ole db initstring",     "provider=sqloledb.1;persist security info=false" };  file.writealllines("test.udl", lines); process p = process.start("test.udl"); p.waitforexit(); 

however, error when trying open file:

file cannot opened. ensure valid data link file.

this strange because created empty file, named something.udl, opened it, clicked ok, , opened contents of file was:

[oledb] ; after line ole db initstring provider=sqloledb.1;persist security info=false 

but there newline character @ end of connection string. used kdiff compare file , file created in program , said "files equal text not binary equal" or effect.

i believe has how file.writealllines method writes strings. attempted use different encodings method no success. ideas on going wrong?

i using this msdn link reference udl files. interesting note if open new text file , past in of lines in lines array, arrive @ same error.

all need use unicode encoding:

file.writealllines("test.udl", lines, encoding.unicode); 

Comments