Home Forums Programming SMO/RMO/DMO Running .sql file using C# .Net - Accents Problem RE: Running .sql file using C# .Net - Accents Problem

  • Can you attach a sample file, maybe a test file that exhibits the behavior but doesn't do anything important?

    If it *is* an encoding problem and you can determine what encoding the source file is using, then the ReadAllText() method may be able to help. It takes a second parameter that specifies the encoding of the source file. If the file is, in fact, Unicode-encoded, then maybe this will work. Replace the line:

    string script = File.ReadAllText(sqlCommandFilePath);

    With this:

    string script = File.ReadAllText(sqlCommandFilePath, System.Text.Encoding.Unicode);

    If it's an encoding issue then it's possible that it's encoded in something other than Unicode (and the enumerations of System.Text.Encoding may contain the one you need if it's not Unicode), but maybe if you can attach a sample file, we'll be able to tell if this is really the problem.

    You can also use Windows Notepad to see the encoding...open the file in Notepad and then do a "File/Save As...". In the dialog box that appears, you should see an "Encoding" drop-down that will show the current encoding of the file. If it's other than "ASCII" then that's the encoding to specify in your code. If it shows as "ASCII" then I don't think it's an encoding problem, it must be some other issue, maybe on the SQL Server side -- do code page or collation settings or something come into play? I don't know.