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

  • I'm not sure what the problem is, but this works fine for me so I don't think the problem is the accents...

    declare @table table ( x varchar(255) )

    declare @my_value varchar(100)

    set @my_value = 'This will select everything fróm my táblé'

    insert into @table (x) values (@my_value)

    select * from @table

    Maybe it's a Unicode conversion problem when you're reading the file, I dunno. Is there a particular reason for your using the Microsoft.SqlServer.Management assemblies? If not, just use System.Data and System.Data.SqlClient, and use the File object to read your file instead of FileInfo, something like this:

    using System;

    using System.Data;

    using System.Data.SqlClient;

    using System.IO;

    namespace ConsoleApplication1

    {

    static class Program

    {

    static void Main(string[] args)

    {

    string sqlConnectionString = "<your connection string here>";

    using (SqlConnection conn = new SqlConnection(sqlConnectionString))

    {

    string sqlCommandFilePath = "<path to your file>";

    if (File.Exists(sqlCommandFilePath))

    {

    string script = File.ReadAllText(sqlCommandFilePath);

    using (SqlCommand cmd = new SqlCommand(script, conn))

    {

    int affectedRows = cmd.ExecuteNonQuery();

    }

    }

    }

    }

    }

    }

    Try this, see if it works any better.