How do you import a large MS SQL .sql file?

前端 未结 11 1366
心在旅途
心在旅途 2020-11-28 00:20

I use RedGate SQL data compare and generated a .sql file, so I could run it on my local machine. But the problem is that the file is over 300mb, which means I can\'t do copy

11条回答
  •  一整个雨季
    2020-11-28 00:58

    I am using MSSQL Express 2014 and none of the solutions worked for me. They all just crashed SQL. As I only needed to run a one off script with many simple insert statements I got around it by writing a little console app as a very last resort:

    class Program
    {
        static void Main(string[] args)
        {
            RunScript();
        }
    
        private static void RunScript()
        {
            My_DataEntities db = new My_DataEntities();
    
            string line;
    
            System.IO.StreamReader file =
               new System.IO.StreamReader("c:\\ukpostcodesmssql.sql");
            while ((line = file.ReadLine()) != null)
            {
                db.Database.ExecuteSqlCommand(line);
            }
    
            file.Close();
        }
    }
    

提交回复
热议问题